# Strange sort behaviour, values replaced

**URL:** <https://discuss.elastic.co/t/strange-sort-behaviour-values-replaced/15443>\
**Category:** Elasticsearch\
**Created:** [January 28, 2014, 8:30am UTC](https://discuss.elastic.co/t/strange-sort-behaviour-values-replaced/15443 "2014-01-28T08:30:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [January 28, 2014, 8:30am UTC](https://discuss.elastic.co/t/strange-sort-behaviour-values-replaced/15443/1 "2014-01-28T08:30:27Z")

</div>

Hello everyone.

Yesterday, I noticed a strange behaviour in the sorting of the data, in one  
of my clusters.  
I have a request like this :

> {  
> "size" : 25,  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "match\_all" : {}  
> },  
> "filter" : {  
> "and" : {  
> "filters" : [{  
> "and" : {  
> "filters" : [{  
> "range" : {  
> "myDateField" : {  
> "from" : "2013-09-26",  
> "to" : "2014-01-27",  
> "include\_lower" : true,  
> "include\_upper" : true  
> }  
> }  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }  
> },  
> "fields" : ["fieldToSortOn1",  
> "fieldToSortOn2",  
> ],  
> "sort" : [{  
> "fieldToSortOn1" : {  
> "asc"  
> }  
> }, {  
> "fieldToSortOn1" : {  
> "asc"  
> }  
> }  
> ]  
> }

So, as you see, I ask for two fields, and I request the results to be  
sorted by those fields.

The problem is that I get results like these :

> {  
> \_index: myIndex  
> \_type: myType  
> \_id: 5454245454146  
> \_score: null  
> fields: {  
> fieldToSortOn1: 13207580  
> fieldToSortOn2: 1  
> }  
> sort: [  
> 13207580  
> 9223372036854776000  
> ]  
> }

The "fields" part is ok, I indeed get the values present in my index. But  
es didn't use the value of the second field to sort, it used that big  
number instead, and so, the result is threw at the end and the sort is all  
wrong. It doesn't happen to all the documents, but it happens enougn to be  
a serious issue (I'd say a sixth of the docs seems to be affected).  
By luck, this is happening on the development environmentI have the exact  
same index on my production environment, and there, I do not have any  
problems.

Prior to this, we had a problem, on this cluster. A human error caused that  
cluster to lose a bunch of shards. We deleted the indices with missing  
shards and kept those who were complete. That indice was, of course, kept,  
as it was still complete. in the end, we got back a green state and could  
issue queries.

Can that strange sort behavior be linked to that problem, as I suspect? If  
so, thats a real problem. Indeed, the cluster says that everything is fine  
(green state) but the sort is broken. If that were to happen in production,  
we would be in a world of pain and misery.  
Did that happens to anyone else?  
Any help would be welcome.  
Thanks,  
Deny

--  
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/55b3ed1e-d451-4f91-b91c-a3c1dddd2bc9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55b3ed1e-d451-4f91-b91c-a3c1dddd2bc9%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [January 28, 2014, 8:57am UTC](https://discuss.elastic.co/t/strange-sort-behaviour-values-replaced/15443/2 "2014-01-28T08:57:43Z")

</div>

Sorry, I couldn't find a way to edit my first post.  
I made a typo. Of course in the query, the sort is :

> "sort" : [{  
> "fieldToSortOn1" : {  
> "asc"  
> }  
> }, {  
> "fieldToSortOn2" : {  
> "asc"  
> }  
> }  
> ]

So that is not the problem.

--  
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/2f36d2c8-b4cc-49b9-ba9a-e36272743f0d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2f36d2c8-b4cc-49b9-ba9a-e36272743f0d%40googlegroups.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, 1:54am UTC](https://discuss.elastic.co/t/strange-sort-behaviour-values-replaced/15443/3 "2017-07-06T01:54:28Z")

</div>


