Use case:
I want to fetch multiple documents by document ID, in a single query. To reduce network calls.
I was exploring the optimal way to write this query. There are multiple ways I find that could do this but I am not sure which is the most optimal way in case of smaller queries (query with less than 100 ID to find) & larger queries (query with greater than 1000 ID to find)
listing down the ways by which we can do it
- Single Query with Terms Query: Sending a query with a terms query targeting multiple values for a specific field to streamline the request process.
GET /index/_search
{
"query": {
"terms": {
"keys": ["key1", "key2", "key3"]
}
}
}
-
Multi-Get Request (GET //_mget): Retrieving multiple documents in a single request by specifying their IDs, providing efficient retrieval with reduced network overhead.
-
Multi-Search Request (POST /_msearch): Executing multiple search requests within a single HTTP request, useful for scenarios requiring simultaneous execution of several queries.