Optimizing Document Retrieval from Elasticsearch: Which Method Works Best?

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

  1. 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"]
    }
  }
}
  1. Multi-Get Request (GET //_mget): Retrieving multiple documents in a single request by specifying their IDs, providing efficient retrieval with reduced network overhead.

  2. Multi-Search Request (POST /_msearch): Executing multiple search requests within a single HTTP request, useful for scenarios requiring simultaneous execution of several queries.

If you know the document IDs I would expect the multi-get API to be the best one as it will retrieve documents even before they are searchable. I would however recommend you test for yourself as this may vary by use case.