'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 1:[1]
From Elasticsearch 5.1 the query looks like:
GET /my_alias_name/_search/
{
"query": {
"bool": {
"filter": {
"term": {
"_id": "AUwNrOZsm6BwwrmnodbW"
}
}
}
}
}
Solution 2:[2]
7.2 version Docs suggest:
GET /_search
{
"query": {
"ids" : {
"values" : ["1", "4", "100"]
}
}
}
Response should look like:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "indexwhatever",
"_type": "_doc",
"_id": "anyID",
"_score": 1.0,
"_source": {
"field1": "value1",
"field2": "value2"
}
}
]
}
}
Solution 3:[3]
In case you want to find a document with some internal id with curl:
curl -X GET 'localhost:9200/_search?q=id:42&pretty'
Solution 4:[4]
Following Elasticsearch 8.2 Doc, you can retrieve a single document by using GET API:
GET my-index-000001/_doc/0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shams |
| Solution 2 | michaelbn |
| Solution 3 | Aliaksei |
| Solution 4 | Cong |
