How to request a single document by _id via alias?

Mischa Arefiev picture Mischa Arefiev · Mar 12, 2015 · Viewed 14.5k times · Source

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)?

Answer

Heschoon picture Heschoon · Mar 12, 2015

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