1
votes

We have a requirement where in we need to query across multiple indices as follows
We are using ElasticSearch 5.1.1.
http://localhost:9200/index1,index2,index3/type1,type2/_search
query:

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

However we may not know in advance if the index is present or not , we get following error if either of above indices is not present.

{
    "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
}

One obvious way is to check if index is already present or not but I would like to avoid that extra call.
Note: At least 1 index will always be present
Is it possible to avoid this Exception ?
Thanks in advance !!

1
Why not using index* instead then and let ES resolve the concrete indices? - Val
Thanks for reply Val ! But I think that will reduce the searching speed, since we have more than 300 indices with same pattern i.e "index" , and also we don't want to expose all indices to consumer,we want to expose only the ones he is authorized to access. - SSG
You should try ;-) - Val

1 Answers

4
votes

"ignore_unavailable" is the solution for this. Pass this as a query parameter in search url. Exa. http://localhost:9200/index1,index2/type/_search?ignore_unavailable

This will not give 404 even if either of the indices are not present