The MultiGet api can be used to fetch multiple documents based on given ids. (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html)
Is it possible to add more filters to this operation? Given a list of ids, I only want to find the documents for which 'color' = 'green'.
Let's say the following documents exist:
Get documents with ids 1, 2 or 4, for which the color is "Green".
[Doc 1, Doc 4]
GET /_mget
{
"docs": [
{
"_index": "my-index-000001",
"_id": "1"
},
{
"_index": "my-index-000001",
"_id": "2"
},
{
"_index": "my-index-000001",
"_id": "4"
}
]
}
or using NEST in C#:
var ids = new List<string> {"1", "2", "4"};
var result = await _elasticClient
.MultiGetAsync(s => s
.Index("my-index-000001")
.GetMany<SomeRecordObject>(ids)
);
So I'm actually looking for a way to add a Bool query to the MultiGet query (I think). Anyone who can point me towards the right direction?
multi get is only for getting multiple documents by id. If you need to perform querying or filtering, then a search query is needed.
Note that multi get and search have different behaviour when it comes to just indexed documents. With multi get, a just indexed document can be immediately retrieved using its id. With search however, a document will only appear in search results once the index is refreshed (refresh interval elapses (by default, 1 second) or index is manually refreshed with the refresh API).