2017-08-02 437 views
1

我们有一个要求,我们需要在多个索引中进行查询,如下所示
我们使用的是ElasticSearch 5.1.1。
http://localhost:9200/index1,index2,index3/type1,type2/_search
查询:ElasticSearch在多索引,多类型搜索时返回404

{ 
"query": { 
    "multi_match": { 
    "query": "data", 
    "fields": ["status"] 
    } 
} 
} 

但是大家可能不知道事先如果指数存在或不存在,我们得到以下错误,如果任何上述指标的不存在。

{ 
    "error": { 
     "root_cause": [ 
      { 
       "type": "index_not_found_exception", 
       "reason": "no such index", 
       "resource.type": "index_or_alias", 
       "resource.id": "index3", 
       "index_uuid": "_na_", 
       "index": "index3" 
      } 
     ], 
     "type": "index_not_found_exception", 
     "reason": "no such index", 
     "resource.type": "index_or_alias", 
     "resource.id": "index3", 
     "index_uuid": "_na_", 
     "index": "index3" 
    }, 
    "status": 404 
} 

一个显而易见的方法是检查索引是否已经存在或不是,但我想避免额外的调用。
注意:至少有1个索引将始终存在
是否可以避免此异常?
在此先感谢!

+0

为什么不使用'指数*'存在,而不是那么让ES解决具体的指标? – Val

+0

感谢您的回复Val!但我认为这会降低搜索速度,因为我们有超过300个相同模式的索引,即“索引”,并且我们也不想将所有索引公开给消费者,我们只想公开他被授权的索引访问。 – SSG

+0

您应该尝试;-) – Val

回答

相关问题