# \_mget vs \_search for large amount of documents

**URL:** <https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521>\
**Category:** Elasticsearch\
**Created:** [July 28, 2023, 9:33am UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521 "2023-07-28T09:33:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hattorihanzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hattorihanzo/32/124021_2.png) [@hattorihanzo](https://discuss.elastic.co/u/hattorihanzo)\
**Post date:** [July 28, 2023, 9:33am UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521/1 "2023-07-28T09:33:38Z")

</div>

Hi there! I'm looking for some guidance around what's the most fit way to retrieve a large amount of documents (\>=1000) when you know their ID. I'd like it to be fast, yet efficient and not put unnecessary strain on ES since this lookup routine will run very often.

The mget documentation doesn't give any pointers as to how it's implemented or how how it's different than using a \_search with a terms query. Are there usecases fit to tackle one thing over the other? It's not clear.

Purely on speed - both approaches seem to be fast and working fine with a large amount of documents, but reading through [this thread](https://discuss.elastic.co/t/multiget-mget-api-performance/289813/2) made me think that mget does N parallel individual "get" operations which seems unnecessary and inefficient.

For retrieving N (large amount of) documents I'd imagine a batched approach would be much more fit (instead of running N parallel gets, you run J batches of retrieval, J being a much smaller number than N.) With that in mind, I'm guessing a \_search terms query does this "batched" approach and is more lean but what do I know! This is pure speculation so I'd like to ask for some guidance around what each thing does.

---

<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:** [July 28, 2023, 10:13am UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521/2 "2023-07-28T10:13:21Z")

</div>

I would expect the mget approach to be as fast or faster as terms queries with large number of terms can be slow.

---

<div class="post-metadata">

**Author:** ![hattorihanzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hattorihanzo/32/124021_2.png) [@hattorihanzo](https://discuss.elastic.co/u/hattorihanzo)\
**Post date:** [July 28, 2023, 12:12pm UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521/3 "2023-07-28T12:12:59Z")

</div>

Great - thanks for the input. Do you know if the stress/load of the two is in the same ballpark?

I'm asking because sometimes speed is not synonymous with efficiency. For example, you can have a process that gains speed by opening 1000 concurrent threads and another process that's slower, but it uses a more conservative e.g. 5 threads. In this scenario I'd consider the first process to be more "stressful" to a database. Not sure if that thinking applies here.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 28, 2023, 12:25pm UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521/4 "2023-07-28T12:25:50Z")

</div>

I have asked internally about this question because I honestly don't know.  
My guts feeling is that if the number of items to retrieve is low (let say 100), than mget might be better.  
But if you compare a 10000 mget vs a 10000 search on a single shard, I'd expect search to be more efficient because of the Lucene optimizations behind the scene...

But I'm waiting for an answer about this very good question 😉

---

<div class="post-metadata">

**Author:** ![hattorihanzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hattorihanzo/32/124021_2.png) [@hattorihanzo](https://discuss.elastic.co/u/hattorihanzo)\
**Post date:** [July 28, 2023, 12:40pm UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521/5 "2023-07-28T12:40:39Z")

</div>

Amazing, thank you! 🙏 If this ends up being fruitful we can potentially add something to the docs

---

<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:** [August 25, 2023, 12:41pm UTC](https://discuss.elastic.co/t/mget-vs-search-for-large-amount-of-documents/339521/6 "2023-08-25T12:41:05Z")

</div>

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