2017-08-02 441 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

回答

相關問題