# Sorting and pagination

**URL:** <https://discuss.elastic.co/t/sorting-and-pagination/21192>\
**Category:** Elasticsearch\
**Created:** [December 10, 2014, 3:48pm UTC](https://discuss.elastic.co/t/sorting-and-pagination/21192 "2014-12-10T15:48:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sotiris\_Beis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sotiris_beis/32/1052_2.png) [@Sotiris\_Beis](https://discuss.elastic.co/u/Sotiris_Beis)\
**Post date:** [December 10, 2014, 3:48pm UTC](https://discuss.elastic.co/t/sorting-and-pagination/21192/1 "2014-12-10T15:48:13Z")

</div>

Hi all,

I was wondering how the scroing works when I ask for paginating results. I  
run a test with the following search requests:

_Request 1_  
I run the following search request and write the results in a file.

SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX\_NAME)  
.setSize(10)  
.setQuery(queryBuilder);  
SearchResponse searchResponse =  
searchRequestBuilder.execute()  
.actionGet();

_Request 2_  
I run the folloing search requests and write the results in a file  
(actually two files, one for each request).

SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX\_NAME)  
.setFrom(0)  
.setSize(5)  
.setQuery(queryBuilder);  
SearchResponse searchResponse =  
searchRequestBuilder.execute()  
.actionGet();

SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX\_NAME)  
.setFrom(1)  
.setSize(5)  
.setQuery(queryBuilder);  
SearchResponse searchResponse =  
searchRequestBuilder.execute()  
.actionGet();

After that I check if I join the two files from the second request if it  
will be the same with the first one. Unfortunately, I noticed that the  
results from the second request are not sorted in a right way like the  
results from the first one. (I am not using any special sorting so I  
suppose that the sorting should be done by the relevance score).

Does anyone knows more information about this issue?

FYI. I use elasticsearch 1.4.0

Cheers,  
Sotiris

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/dae2524c-a990-45d5-a4fc-c3fbc0c2741d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dae2524c-a990-45d5-a4fc-c3fbc0c2741d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 10, 2014, 4:52pm UTC](https://discuss.elastic.co/t/sorting-and-pagination/21192/2 "2014-12-10T16:52:03Z")

</div>

Are you sure you want the hits 0-5 and 1-6 in request 2? I assume you want  
hits 0-5 and 5-10.

Jörg

On Wed, Dec 10, 2014 at 4:48 PM, Sotiris Beis [sot.beis@gmail.com](mailto:sot.beis@gmail.com) wrote:

> Hi all,
> 
> I was wondering how the scroing works when I ask for paginating results. I  
> run a test with the following search requests:
> 
> _Request 1_  
> I run the following search request and write the results in a file.
> 
> SearchRequestBuilder searchRequestBuilder = client.prepareSearch(  
> INDEX\_NAME)  
> .setSize(10)  
> .setQuery(queryBuilder);  
> SearchResponse searchResponse =  
> searchRequestBuilder.execute()  
> .actionGet();
> 
> _Request 2_  
> I run the folloing search requests and write the results in a file  
> (actually two files, one for each request).
> 
> SearchRequestBuilder searchRequestBuilder = client.prepareSearch(  
> INDEX\_NAME)  
> .setFrom(0)  
> .setSize(5)  
> .setQuery(queryBuilder);  
> SearchResponse searchResponse =  
> searchRequestBuilder.execute()  
> .actionGet();
> 
> SearchRequestBuilder searchRequestBuilder = client.prepareSearch(  
> INDEX\_NAME)  
> .setFrom(1)  
> .setSize(5)  
> .setQuery(queryBuilder);  
> SearchResponse searchResponse =  
> searchRequestBuilder.execute()  
> .actionGet();
> 
> After that I check if I join the two files from the second request if it  
> will be the same with the first one. Unfortunately, I noticed that the  
> results from the second request are not sorted in a right way like the  
> results from the first one. (I am not using any special sorting so I  
> suppose that the sorting should be done by the relevance score).
> 
> Does anyone knows more information about this issue?
> 
> FYI. I use elasticsearch 1.4.0
> 
> Cheers,  
> Sotiris
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/dae2524c-a990-45d5-a4fc-c3fbc0c2741d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dae2524c-a990-45d5-a4fc-c3fbc0c2741d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/dae2524c-a990-45d5-a4fc-c3fbc0c2741d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/dae2524c-a990-45d5-a4fc-c3fbc0c2741d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEjA%3DDFLc%3Dx608TNtEx\_YpDzXgHNqi106YoN%2BLk1WmZvQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEjA%3DDFLc%3Dx608TNtEx_YpDzXgHNqi106YoN%2BLk1WmZvQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:44am UTC](https://discuss.elastic.co/t/sorting-and-pagination/21192/3 "2017-07-06T00:44:25Z")

</div>


