# Optimizing Document Retrieval from Elasticsearch: Which Method Works Best?

**URL:** <https://discuss.elastic.co/t/optimizing-document-retrieval-from-elasticsearch-which-method-works-best/353501>\
**Category:** Elastic Search\
**Tags:** elastic-app-search, elastic-workplace-search\
**Created:** [February 17, 2024, 7:46am UTC](https://discuss.elastic.co/t/optimizing-document-retrieval-from-elasticsearch-which-method-works-best/353501 "2024-02-17T07:46:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ONKAR\_SURYAWANSHI](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/onkar_suryawanshi/32/131834_2.png) [@ONKAR\_SURYAWANSHI](https://discuss.elastic.co/u/ONKAR_SURYAWANSHI)\
**Post date:** [February 17, 2024, 7:46am UTC](https://discuss.elastic.co/t/optimizing-document-retrieval-from-elasticsearch-which-method-works-best/353501/1 "2024-02-17T07:46:29Z")

</div>

**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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 19, 2024, 6:38am UTC](https://discuss.elastic.co/t/optimizing-document-retrieval-from-elasticsearch-which-method-works-best/353501/2 "2024-02-19T06:38:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 18, 2024, 6:39am UTC](https://discuss.elastic.co/t/optimizing-document-retrieval-from-elasticsearch-which-method-works-best/353501/3 "2024-03-18T06:39:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
