Reputation: 2113
All the documents in the elasticsearch index have an id
field.
I have an array of id
s and I want to fetch documents with id
s in this array. What is the elasticsearch query for this task?
Upvotes: 0
Views: 2590
Reputation: 2518
Saga, the most efficient query for this is an mget
:
Example :
GET myindex/_mget
{
"docs" : [
{
"_id" : "fIjOTW8BkTKnAOE5HVit"
},
{
"_id" : "fojOTW8BkTKnAOE5UliD"
}
]
}
More information on Elasticsearch's documentation
Upvotes: 1
Reputation: 7770
let's say you have ids in array like ["36088175", "36088176"]
The query will be
{
"query" : {
"terms" : {
"_id" : ["36088175", "36088176"]
}
}
}
see terms query for more details - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
Upvotes: 2