# ElasticSearch pagination - from/size vs Search After for number of hits less than 10k

**URL:** <https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855>\
**Category:** Elasticsearch\
**Created:** [May 28, 2022, 1:00pm UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855 "2022-05-28T13:00:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ano](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ano](https://discuss.elastic.co/u/ano)\
**Post date:** [May 28, 2022, 1:00pm UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855/1 "2022-05-28T13:00:54Z")

</div>

Hi,

I'm using Elasticsearch, and for paginating the search results, should I use the simple from/size, or should I go with search after. I've read that if the number of hits is less than 10k, then from/size is acceptable. Even though my total search space is much more than 10k, but the number of hits/matches I'm expecting is around 5k at max.

For this, would there be a lot of performance difference between from/size and search after? I'm leaning towards from/size since search after is relatively trickier to implement, specially when there's a requirement for going back to a previous page.

Thanks!

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 28, 2022, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855/2 "2022-05-28T14:07:27Z")

</div>

Hi!

I don't know if you read the posts below, but maybe I can help you.

[Article Opster](https://opster.com/guides/elasticsearch/how-tos/elasticsearch-pagination-techniques/)  
[Question Stackoverflow](https://stackoverflow.com/questions/68707609/elastic-search-how-exactly-is-search-after-better-than-primitive-paginationfro)

---

<div class="post-metadata">

**Author:** ![ano](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ano](https://discuss.elastic.co/u/ano)\
**Post date:** [May 31, 2022, 3:35am UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855/4 "2022-05-31T03:35:15Z")

</div>

Hi,  
Thank you for your response, and the helpful links!  
But is there some threshold/recommendation as to what would be the maximum size of the result set on which from/size and search after would perform roughly the same?

I understand that it will also depend on other factors, like query logic, or size of the analysed data we're querying on(The size of 1 document for us is about 5-10kb).

We're building a e-commerce type search from scratch, and I don't expect the search results of a query to be more than 500, or 1k.  
It's difficult to to do a POC on both approaches, since we don't have data in that scale yet, and I'm leaning towards from/size. Hence, was looking for some empirical data/advice from people with more experience on this.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 31, 2022, 11:50pm UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855/5 "2022-05-31T23:50:54Z")

</div>

It seems that one of the requirements is to have access to the previous page, in which case I would also use from/size respecting the restrictions of this implementation.

---

<div class="post-metadata">

**Author:** ![ano](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ano](https://discuss.elastic.co/u/ano)\
**Post date:** [June 1, 2022, 3:16pm UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855/6 "2022-06-01T15:16:52Z")

</div>

Thanks a lot!

---

<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:** [June 29, 2022, 3:17pm UTC](https://discuss.elastic.co/t/elasticsearch-pagination-from-size-vs-search-after-for-number-of-hits-less-than-10k/305855/7 "2022-06-29T15:17:50Z")

</div>

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