elasticsearchelasticsearch-query

How to request a single document by _id via alias?


Is it possible to request a single document by its id by querying an alias, provided that all keys across all indices in the alias are unique (it is an external guarantee)?


Solution

  • Yes, querying an alias spanning over multiple indices work the same way as querying one indice.

    Just do this query over the alias:

    POST my_alias_name/_search
    {
        "filter":{
            "term":{"_id": "AUwNrOZsm6BwwrmnodbW"}
        }
    }
    

    EDIT: GET operations are not real searches and can't be done on aliases spanning over multiple indexes. So the following query is in fact no permitted:

    GET my_alias_name/my_type/AUwNrOZsm6BwwrmnodbW