# Can't combine "order" with "size" in 0.90.0?

**URL:** <https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790>\
**Category:** Elasticsearch\
**Created:** [May 3, 2013, 2:59am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790 "2013-05-03T02:59:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [May 3, 2013, 2:59am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/1 "2013-05-03T02:59:55Z")

</div>

I have a simple index with 4 docs containing a "tag" field, with the values  
"alpha", "beta", "delta" and "gamma", respectively. It appears that when I  
restrict the "size" to less than the total number of hits, the "order" is  
ignored. The same request works as expected in 0.20.6.

request:  
{  
"from" : 0,  
"size" : 2,  
"query" : {  
"match\_all" : { }  
},  
"version" : true,  
"sort" : [ {  
"tag" : {  
"order" : "asc"  
}  
} ]  
}

response:  
{  
"took" : 17,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 4,  
"max\_score" : null,  
"hits" : [ {  
"\_index" : "c1cp147rfj",  
"\_type" : "event",  
"\_id" : "bruovacpmo",  
"\_version" : 1,  
"\_score" : null, "\_source" : {"tag":"alpha"},  
"sort" : ["alpha"]  
}, {  
"\_index" : "c1cp147rfj",  
"\_type" : "event",  
"\_id" : "29bv3m8n8a",  
"\_version" : 1,  
"\_score" : null, "\_source" : {"tag":"gamma"},  
"sort" : ["gamma"]  
} ]  
}  
}

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 3, 2013, 9:41am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/2 "2013-05-03T09:41:50Z")

</div>

Hey,

can you provide a complete gist to reproduce (including mapping)? I just  
tried this (with 0.90.0)

curl -v -X PUT localhost:9200/index/type/1 -d '{ "tags" : ["alpha"] }'  
curl -v -X PUT localhost:9200/index/type/2 -d '{ "tags" : ["beta"] }'  
curl -v -X PUT localhost:9200/index/type/3 -d '{ "tags" : ["gamma"] }'  
curl -v -X PUT localhost:9200/index/type/4 -d '{ "tags" : ["delta"] }'

curl -X POST localhost:9200/index/type/\_search -d '  
{  
"from" : 0,  
"size" : 3,  
"query" : {  
"match\_all" : { }  
},  
"version" : true,  
"sort" : [ {  
"tags" : {  
"order" : "asc"  
}  
} ]  
}  
'

The query returns "alpha" "beta" "delta" hits and looks ok. Maybe I  
overlooked something from your query.

--Alex

On Fri, May 3, 2013 at 4:59 AM, Eric Jain [eric.jain@gmail.com](mailto:eric.jain@gmail.com) wrote:

> I have a simple index with 4 docs containing a "tag" field, with the  
> values "alpha", "beta", "delta" and "gamma", respectively. It appears that  
> when I restrict the "size" to less than the total number of hits, the  
> "order" is ignored. The same request works as expected in 0.20.6.
> 
> request:  
> {  
> "from" : 0,  
> "size" : 2,  
> "query" : {  
> "match\_all" : { }  
> },  
> "version" : true,  
> "sort" : [ {  
> "tag" : {  
> "order" : "asc"  
> }  
> } ]  
> }
> 
> response:  
> {  
> "took" : 17,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 4,  
> "max\_score" : null,  
> "hits" : [ {  
> "\_index" : "c1cp147rfj",  
> "\_type" : "event",  
> "\_id" : "bruovacpmo",  
> "\_version" : 1,  
> "\_score" : null, "\_source" : {"tag":"alpha"},  
> "sort" : ["alpha"]  
> }, {  
> "\_index" : "c1cp147rfj",  
> "\_type" : "event",  
> "\_id" : "29bv3m8n8a",  
> "\_version" : 1,  
> "\_score" : null, "\_source" : {"tag":"gamma"},  
> "sort" : ["gamma"]  
> } ]  
> }  
> }
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [May 3, 2013, 6:21pm UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/3 "2013-05-03T18:21:07Z")

</div>

To replicate the issue, create an index with a single shard and no replicas.

On Fri, May 3, 2013 at 2:41 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> can you provide a complete gist to reproduce (including mapping)? I just  
> tried this (with 0.90.0)
> 
> curl -v -X PUT localhost:9200/index/type/1 -d '{ "tags" : ["alpha"] }'  
> curl -v -X PUT localhost:9200/index/type/2 -d '{ "tags" : ["beta"] }'  
> curl -v -X PUT localhost:9200/index/type/3 -d '{ "tags" : ["gamma"] }'  
> curl -v -X PUT localhost:9200/index/type/4 -d '{ "tags" : ["delta"] }'
> 
> curl -X POST localhost:9200/index/type/\_search -d '  
> {  
> "from" : 0,  
> "size" : 3,  
> "query" : {  
> "match\_all" : { }  
> },  
> "version" : true,  
> "sort" : [ {  
> "tags" : {  
> "order" : "asc"  
> }  
> } ]  
> }  
> '
> 
> The query returns "alpha" "beta" "delta" hits and looks ok. Maybe I  
> overlooked something from your query.
> 
> --Alex
> 
> On Fri, May 3, 2013 at 4:59 AM, Eric Jain [eric.jain@gmail.com](mailto:eric.jain@gmail.com) wrote:
> 
> > I have a simple index with 4 docs containing a "tag" field, with the  
> > values "alpha", "beta", "delta" and "gamma", respectively. It appears that  
> > when I restrict the "size" to less than the total number of hits, the  
> > "order" is ignored. The same request works as expected in 0.20.6.
> > 
> > request:  
> > {  
> > "from" : 0,  
> > "size" : 2,  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "version" : true,  
> > "sort" : [ {  
> > "tag" : {  
> > "order" : "asc"  
> > }  
> > } ]  
> > }
> > 
> > response:  
> > {  
> > "took" : 17,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 4,  
> > "max\_score" : null,  
> > "hits" : [ {  
> > "\_index" : "c1cp147rfj",  
> > "\_type" : "event",  
> > "\_id" : "bruovacpmo",  
> > "\_version" : 1,  
> > "\_score" : null, "\_source" : {"tag":"alpha"},  
> > "sort" : ["alpha"]  
> > }, {  
> > "\_index" : "c1cp147rfj",  
> > "\_type" : "event",  
> > "\_id" : "29bv3m8n8a",  
> > "\_version" : 1,  
> > "\_score" : null, "\_source" : {"tag":"gamma"},  
> > "sort" : ["gamma"]  
> > } ]  
> > }  
> > }
> > 
> > --  
> > 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).
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/W5s1KypYcYw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/W5s1KypYcYw/unsubscribe?hl=en-US).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [May 4, 2013, 10:46pm UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/4 "2013-05-04T22:46:06Z")

</div>

That one is tricky... I can reproduce this and that is in-fact a bug. I  
opened an issue with some explanation.

> <https://github.com/elastic/elasticsearch/issues/2991>
>
> The BytesRefOrdValComparator uses \`Ordinals.Docs.getNumOrdinals() -1\` as the upp…erbound for the binarysearch. The \`-1\` causes that we ignore the last value in the segment. 
> 
> This is kind of a very tricky bug since it only happens if we need to binary-search to align ords and the bottom of the sort queue is greater than the largest value in the segment but less than the second largest. This was causing an issue reported by a user on the mailing list: https://groups.google.com/d/msg/elasticsearch/W5s1KypYcYw/L1UgixO\_gQ4J

thank you very much for raising this.

simon  
On Friday, May 3, 2013 8:21:07 PM UTC+2, Eric Jain wrote:

> To replicate the issue, create an index with a single shard and no  
> replicas.
> 
> On Fri, May 3, 2013 at 2:41 AM, Alexander Reelsen \<[a...@spinscale.de](mailto:a...@spinscale.de)\<javascript:\>\>  
> wrote:
> 
> > Hey,
> > 
> > can you provide a complete gist to reproduce (including mapping)? I just  
> > tried this (with 0.90.0)
> > 
> > curl -v -X PUT localhost:9200/index/type/1 -d '{ "tags" : ["alpha"]  
> > }'  
> > curl -v -X PUT localhost:9200/index/type/2 -d '{ "tags" : ["beta"] }'  
> > curl -v -X PUT localhost:9200/index/type/3 -d '{ "tags" : ["gamma"]  
> > }'  
> > curl -v -X PUT localhost:9200/index/type/4 -d '{ "tags" : ["delta"]  
> > }'
> > 
> > curl -X POST localhost:9200/index/type/\_search -d '  
> > {  
> > "from" : 0,  
> > "size" : 3,  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "version" : true,  
> > "sort" : [ {  
> > "tags" : {  
> > "order" : "asc"  
> > }  
> > } ]  
> > }  
> > '
> > 
> > The query returns "alpha" "beta" "delta" hits and looks ok. Maybe I  
> > overlooked something from your query.
> > 
> > --Alex
> > 
> > On Fri, May 3, 2013 at 4:59 AM, Eric Jain \<[eric...@gmail.com](mailto:eric...@gmail.com)\<javascript:\>\>  
> > wrote:
> > 
> > > I have a simple index with 4 docs containing a "tag" field, with the  
> > > values "alpha", "beta", "delta" and "gamma", respectively. It appears  
> > > that  
> > > when I restrict the "size" to less than the total number of hits, the  
> > > "order" is ignored. The same request works as expected in 0.20.6.
> > > 
> > > request:  
> > > {  
> > > "from" : 0,  
> > > "size" : 2,  
> > > "query" : {  
> > > "match\_all" : { }  
> > > },  
> > > "version" : true,  
> > > "sort" : [ {  
> > > "tag" : {  
> > > "order" : "asc"  
> > > }  
> > > } ]  
> > > }
> > > 
> > > response:  
> > > {  
> > > "took" : 17,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 4,  
> > > "max\_score" : null,  
> > > "hits" : [ {  
> > > "\_index" : "c1cp147rfj",  
> > > "\_type" : "event",  
> > > "\_id" : "bruovacpmo",  
> > > "\_version" : 1,  
> > > "\_score" : null, "\_source" : {"tag":"alpha"},  
> > > "sort" : ["alpha"]  
> > > }, {  
> > > "\_index" : "c1cp147rfj",  
> > > "\_type" : "event",  
> > > "\_id" : "29bv3m8n8a",  
> > > "\_version" : 1,  
> > > "\_score" : null, "\_source" : {"tag":"gamma"},  
> > > "sort" : ["gamma"]  
> > > } ]  
> > > }  
> > > }
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit
> 
> [https://groups.google.com/d/topic/elasticsearch/W5s1KypYcYw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/W5s1KypYcYw/unsubscribe?hl=en-US).
> 
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [May 4, 2013, 11:04pm UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/5 "2013-05-04T23:04:47Z")

</div>

@Alex, I guess you added the docs to quickly so they didn't end up in  
different segments. for this to fail you need to have at least two segments  
🙂

simon

On Sunday, May 5, 2013 12:46:06 AM UTC+2, simonw wrote:

> That one is tricky... I can reproduce this and that is in-fact a bug. I  
> opened an issue with some explanation.
> 
> [BytesRefOrdValComparator ignores highest value in a segment during binarySearch · Issue #2991 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2991)
> 
> thank you very much for raising this.
> 
> simon  
> On Friday, May 3, 2013 8:21:07 PM UTC+2, Eric Jain wrote:
> 
> > To replicate the issue, create an index with a single shard and no  
> > replicas.
> > 
> > On Fri, May 3, 2013 at 2:41 AM, Alexander Reelsen [a...@spinscale.de](mailto:a...@spinscale.de)  
> > wrote:
> > 
> > > Hey,
> > > 
> > > can you provide a complete gist to reproduce (including mapping)? I  
> > > just  
> > > tried this (with 0.90.0)
> > > 
> > > curl -v -X PUT localhost:9200/index/type/1 -d '{ "tags" : ["alpha"]  
> > > }'  
> > > curl -v -X PUT localhost:9200/index/type/2 -d '{ "tags" : ["beta"]  
> > > }'  
> > > curl -v -X PUT localhost:9200/index/type/3 -d '{ "tags" : ["gamma"]  
> > > }'  
> > > curl -v -X PUT localhost:9200/index/type/4 -d '{ "tags" : ["delta"]  
> > > }'
> > > 
> > > curl -X POST localhost:9200/index/type/\_search -d '  
> > > {  
> > > "from" : 0,  
> > > "size" : 3,  
> > > "query" : {  
> > > "match\_all" : { }  
> > > },  
> > > "version" : true,  
> > > "sort" : [ {  
> > > "tags" : {  
> > > "order" : "asc"  
> > > }  
> > > } ]  
> > > }  
> > > '
> > > 
> > > The query returns "alpha" "beta" "delta" hits and looks ok. Maybe I  
> > > overlooked something from your query.
> > > 
> > > --Alex
> > > 
> > > On Fri, May 3, 2013 at 4:59 AM, Eric Jain [eric...@gmail.com](mailto:eric...@gmail.com) wrote:
> > > 
> > > > I have a simple index with 4 docs containing a "tag" field, with the  
> > > > values "alpha", "beta", "delta" and "gamma", respectively. It appears  
> > > > that  
> > > > when I restrict the "size" to less than the total number of hits, the  
> > > > "order" is ignored. The same request works as expected in 0.20.6.
> > > > 
> > > > request:  
> > > > {  
> > > > "from" : 0,  
> > > > "size" : 2,  
> > > > "query" : {  
> > > > "match\_all" : { }  
> > > > },  
> > > > "version" : true,  
> > > > "sort" : [ {  
> > > > "tag" : {  
> > > > "order" : "asc"  
> > > > }  
> > > > } ]  
> > > > }
> > > > 
> > > > response:  
> > > > {  
> > > > "took" : 17,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 1,  
> > > > "successful" : 1,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 4,  
> > > > "max\_score" : null,  
> > > > "hits" : [ {  
> > > > "\_index" : "c1cp147rfj",  
> > > > "\_type" : "event",  
> > > > "\_id" : "bruovacpmo",  
> > > > "\_version" : 1,  
> > > > "\_score" : null, "\_source" : {"tag":"alpha"},  
> > > > "sort" : ["alpha"]  
> > > > }, {  
> > > > "\_index" : "c1cp147rfj",  
> > > > "\_type" : "event",  
> > > > "\_id" : "29bv3m8n8a",  
> > > > "\_version" : 1,  
> > > > "\_score" : null, "\_source" : {"tag":"gamma"},  
> > > > "sort" : ["gamma"]  
> > > > } ]  
> > > > }  
> > > > }
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit
> > 
> > [https://groups.google.com/d/topic/elasticsearch/W5s1KypYcYw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/W5s1KypYcYw/unsubscribe?hl=en-US).
> > 
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 19, 2013, 10:20pm UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/6 "2013-06-19T22:20:12Z")

</div>

btw I'm still seeing an ordering issue in 0.90.1: When retrieving 10 docs  
(out of 20) ordered by the value of a field, one of the first 9 docs  
sometimes appears in position 10. Haven't been able to reproduce this with  
a standalone elasticsearch, only in embedded mode.

Anyone else notice this?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [June 20, 2013, 7:55am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/7 "2013-06-20T07:55:24Z")

</div>

hey there are several situations where this can happen. ie if another doc  
has the same value we use the internal doc ID as a tie-breaker. So you you  
page to the second page and hit a different shard the docs might have a  
different internal Id due to segment merges etc. so the order is slightly  
different. you can use a preference on the search request so make sure you  
hit the same shards. is it possible that you see this?

simon

On Thursday, June 20, 2013 12:20:12 AM UTC+2, Eric Jain wrote:

> btw I'm still seeing an ordering issue in 0.90.1: When retrieving 10 docs  
> (out of 20) ordered by the value of a field, one of the first 9 docs  
> sometimes appears in position 10. Haven't been able to reproduce this with  
> a standalone elasticsearch, only in embedded mode.
> 
> Anyone else notice this?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [June 20, 2013, 8:14am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/8 "2013-06-20T08:14:39Z")

</div>

Hi Simon,

do I read it correctly that using preference is now de facto recommended  
for pagination with order?

Regards,  
Lukas

On Thu, Jun 20, 2013 at 9:55 AM, simonw  
[simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)wrote:

> hey there are several situations where this can happen. ie if another doc  
> has the same value we use the internal doc ID as a tie-breaker. So you you  
> page to the second page and hit a different shard the docs might have a  
> different internal Id due to segment merges etc. so the order is slightly  
> different. you can use a preference on the search request so make sure you  
> hit the same shards. is it possible that you see this?
> 
> simon
> 
> On Thursday, June 20, 2013 12:20:12 AM UTC+2, Eric Jain wrote:
> 
> > btw I'm still seeing an ordering issue in 0.90.1: When retrieving 10 docs  
> > (out of 20) ordered by the value of a field, one of the first 9 docs  
> > sometimes appears in position 10. Haven't been able to reproduce this with  
> > a standalone elasticsearch, only in embedded mode.
> > 
> > Anyone else notice this?
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [June 20, 2013, 2:29pm UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/9 "2013-06-20T14:29:24Z")

</div>

Lukas,

what do you mean by de facto recommended? I mean you have realtime changes  
so you can use preference to reduce the risk but you might hit a reopen and  
this will still make you list different. Yet, if you use scroll you can be  
on the safe side but that will hold on to resources longer.

simon

On Thursday, June 20, 2013 10:14:39 AM UTC+2, Lukáš Vlček wrote:

> Hi Simon,
> 
> do I read it correctly that using preference is now de facto recommended  
> for pagination with order?
> 
> Regards,  
> Lukas
> 
> On Thu, Jun 20, 2013 at 9:55 AM, simonw \<[simon.w...@elasticsearch.com](mailto:simon.w...@elasticsearch.com)\<javascript:\>
> 
> > wrote:
> 
> > hey there are several situations where this can happen. ie if another doc  
> > has the same value we use the internal doc ID as a tie-breaker. So you you  
> > page to the second page and hit a different shard the docs might have a  
> > different internal Id due to segment merges etc. so the order is slightly  
> > different. you can use a preference on the search request so make sure you  
> > hit the same shards. is it possible that you see this?
> > 
> > simon
> > 
> > On Thursday, June 20, 2013 12:20:12 AM UTC+2, Eric Jain wrote:
> > 
> > > btw I'm still seeing an ordering issue in 0.90.1: When retrieving 10  
> > > docs (out of 20) ordered by the value of a field, one of the first 9 docs  
> > > sometimes appears in position 10. Haven't been able to reproduce this with  
> > > a standalone elasticsearch, only in embedded mode.
> > > 
> > > Anyone else notice this?
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 20, 2013, 5:40pm UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/10 "2013-06-20T17:40:39Z")

</div>

On Thu, Jun 20, 2013 at 12:55 AM, simonw  
[simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com) wrote:

> is it possible that you see this?

No, because the field I am sorting on has a unique value for each document.

Strangely, I'm unable to reproduce the issue today, even though the  
test case is quite simple. I'll try again tomorrow, could be an  
odd-day-only bug 🙂

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [June 25, 2013, 11:50am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/11 "2013-06-25T11:50:24Z")

</div>

Hi Simon,

I was looking at the fix to better understand what was going on. I think I  
am basically getting it (the -1 was the problem as you explained in the  
#2991).

Now, if I understand correctly, one might still get different results (i.e.  
two same queries yielding different order of hits) when matching documents  
have same value and they can not all fit into the size window. When docs  
have the same value (by which they are being sorted on) then the sort is  
influenced by internal docID and this internal docID changes when these  
documents are reindexed and seen after reopen. Is that what is happening?

Thanks,  
Lukas

On Thu, Jun 20, 2013 at 4:29 PM, simonw  
[simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)wrote:

> Lukas,
> 
> what do you mean by de facto recommended? I mean you have realtime changes  
> so you can use preference to reduce the risk but you might hit a reopen and  
> this will still make you list different. Yet, if you use scroll you can be  
> on the safe side but that will hold on to resources longer.
> 
> simon
> 
> On Thursday, June 20, 2013 10:14:39 AM UTC+2, Lukáš Vlček wrote:
> 
> > Hi Simon,
> > 
> > do I read it correctly that using preference is now de facto recommended  
> > for pagination with order?
> > 
> > Regards,  
> > Lukas
> > 
> > On Thu, Jun 20, 2013 at 9:55 AM, simonw \<simon.w...@\*\*[elasticsearch.com](http://elasticsearch.com)\>wrote:
> > 
> > > hey there are several situations where this can happen. ie if another  
> > > doc has the same value we use the internal doc ID as a tie-breaker. So you  
> > > you page to the second page and hit a different shard the docs might have a  
> > > different internal Id due to segment merges etc. so the order is slightly  
> > > different. you can use a preference on the search request so make sure you  
> > > hit the same shards. is it possible that you see this?
> > > 
> > > simon
> > > 
> > > On Thursday, June 20, 2013 12:20:12 AM UTC+2, Eric Jain wrote:
> > > 
> > > > btw I'm still seeing an ordering issue in 0.90.1: When retrieving 10  
> > > > docs (out of 20) ordered by the value of a field, one of the first 9 docs  
> > > > sometimes appears in position 10. Haven't been able to reproduce this with  
> > > > a standalone elasticsearch, only in embedded mode.
> > > > 
> > > > Anyone else notice this?
> > > > 
> > > > --  
> > > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > .
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [October 9, 2013, 12:32am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/12 "2013-10-09T00:32:46Z")

</div>

On Wednesday, June 19, 2013 3:20:12 PM UTC-7, Eric Jain wrote:

> btw I'm still seeing an ordering issue in 0.90.1: When retrieving 10 docs  
> (out of 20) ordered by the value of a field, one of the first 9 docs  
> sometimes appears in position 10. Haven't been able to reproduce this with  
> a standalone elasticsearch, only in embedded mode.

Turns out the field I was sorting on was not indexed, so I guess  
elasticsearch decided to return the results in doc ID order rather than  
failing...

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:13am UTC](https://discuss.elastic.co/t/cant-combine-order-with-size-in-0-90-0/11790/13 "2017-07-06T02:13:15Z")

</div>


