Search code examples
elasticsearch

Why Termslookup does not work on aliases?


I have this termlookup query fetching(and not writing) docs:

{
  "query": {
    "terms": {
        "name" : {
            "index" : "people",
            "id" : "2",
            "path" : "name"
        }
    }
  }
}

When "people" is associated with multiple indices I get this error:

alias [people] has more than one index associated with it [people1, people-archive], can't execute a single index op

So if I want to search in multiple indices it is not possible? Or should I specify an array of indices somehow instead of an alias?


Solution

  • You can only define an index or an alias that associated with only one index in terms lookup query. Try the following API call if it's fail terms lookup query will fail too.

    GET people/_doc/2
    

    So if I want to search in multiple indices it is not possible? Or should I specify an array of indices somehow instead of an alias?

    Yes you can search multiple indices like the following.

    GET index1,index2/_search
    

    or

    GET index*/_search
    

    But you can't use some specific queries for multiple indices like terms lookup because it should get the value from one specific doc.

    If you want to use terms lookup query like in your example, you should send the query to indices one by one.

    https://www.elastic.co/guide/en/elasticsearch/reference/7.10/query-dsl-terms-query.html#query-dsl-terms-lookup