# On the advantage of search\_after under the hood

**URL:** <https://discuss.elastic.co/t/on-the-advantage-of-search-after-under-the-hood/362744>\
**Category:** Elasticsearch\
**Created:** [July 8, 2024, 10:52pm UTC](https://discuss.elastic.co/t/on-the-advantage-of-search-after-under-the-hood/362744 "2024-07-08T22:52:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chervine\_Majeri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chervine_majeri/32/135892_2.png) [@Chervine\_Majeri](https://discuss.elastic.co/u/Chervine_Majeri)\
**Post date:** [July 8, 2024, 10:52pm UTC](https://discuss.elastic.co/t/on-the-advantage-of-search-after-under-the-hood/362744/1 "2024-07-08T22:52:21Z")

</div>

Hello,

Unless we're reading from a sorted index, it seems like elasticsearch will always read all matching rows into memory and then sort through them.  
Essentially, this makes it so the main advantage of using search\_after over size/from is that using the latter, each node handling the query would need to return a (size+from)-sized dataset to the controller, whereas using the former, they can just each return one page of data.

Is this accurate? are there other benefits that I'm missing?  
Thanks

---

<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 9, 2024, 7:15am UTC](https://discuss.elastic.co/t/on-the-advantage-of-search-after-under-the-hood/362744/2 "2024-07-09T07:15:03Z")

</div>

Please do not open multiple threads on the same issue.

> [@Chervine\_Majeri](#):
>
> Unless we're reading from a sorted index, it seems like elasticsearch will always read all matching rows into memory and then sort through them.

No, this is not at all how it works.

Please see [my response to your other thread](https://discuss.elastic.co/t/iterating-through-large-datasets-in-various-orders-efficiently/362743/2) for additional details.

---

<div class="post-metadata">

**Author:** ![Chervine\_Majeri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chervine_majeri/32/135892_2.png) [@Chervine\_Majeri](https://discuss.elastic.co/u/Chervine_Majeri)\
**Post date:** [July 9, 2024, 8:55am UTC](https://discuss.elastic.co/t/on-the-advantage-of-search-after-under-the-hood/362744/3 "2024-07-09T08:55:14Z")

</div>

Hi,  
Thanks again for the answers on the other thread!

I really don't see them as the same issue, I'm just asking about the internals of "search\_after". I'm reading about ES and I find I'm having tons of questions, and not all of them are answered in the docs/medium articles/etc...

I understand at least one of the benefits (individual nodes can pre-filter and we avoid a lot of transfers to the coordinator), but I'm asking if there's more that I'm missing.

Maybe it was unclear, as I do mention search\_after in the other thread as well.
