# Sorting on \_id in 0.17.8 does not appear to work

**URL:** https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586
**Category:** Elasticsearch
**Created:** [October 13, 2011, 11:48am UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586 "2011-10-13T11:48:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dmcclure1](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dmcclure1](https://discuss.elastic.co/u/dmcclure1)
#### Post date: [October 13, 2011, 11:48am UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586/1 "2011-10-13T11:48:37Z")

</div>

Just moved from 0.15.2 to 0.17.8 and appears that sorting on \_id no  
longer works as expected. Have verified this from command line and in  
a test case using the java apis.

Below are the results from two queries executed from command line, one  
with sort on my own id (myId) and other with sort on \_id. Sort on \_id  
does not work as expected but the other one does. Also, noticed that  
the results for the sort on \_id have no values populated in the "sort"  
output (as in "sort" : [null])

--------------- Data Setup ----------------

curl -XPUT '[http://localhost:9200/sorttest/](http://localhost:9200/sorttest/)' -d '{  
"index":{  
"standard":{  
"type":"standard"  
}  
}  
}  
}}';

curl -XPUT '[http://localhost:9200/sorttest/data/\_mapping](http://localhost:9200/sorttest/data/_mapping)' -d '  
{  
"asset" : {  
"properties" : {  
"myId" : {"type" : "long"},  
"text" : {"type" : "string", "index" : "analyzed",  
"analyzer":"standard"}  
}  
}  
}';

curl -XPUT '[http://localhost:9200/sorttest/data/1](http://localhost:9200/sorttest/data/1)' -d '{  
"text" : "test rec 1",  
"myId" : 1  
}';

curl -XPUT '[http://localhost:9200/sorttest/data/2](http://localhost:9200/sorttest/data/2)' -d '{  
"text" : "test rec 2",  
"myId" : 2  
}';

curl -XPUT '[http://localhost:9200/sorttest/data/3](http://localhost:9200/sorttest/data/3)' -d '{  
"text" : "test rec 3",  
"myId" : 3  
}';

---------- Query with sort on \_id (not working, sort is [null] in  
results) -------------

curl -XGET 127.0.0.1:9200/sorttest/\_search?pretty=true -d '{  
"query" : {  
"match\_all":{}  
},  
"sort" : {  
"\_id":"desc"  
}  
}';

{  
"took" : 78,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : null,  
"hits" : [ {  
"\_index" : "sorttest",  
"\_type" : "data",  
"\_id" : "1",  
"\_score" : null, "\_source" : {  
"text" : "test rec 1",  
"myId" : 1  
},  
"sort" : [null]  
\<======== ????, \_id values do not appear  
}, {  
"\_index" : "sorttest",  
"\_type" : "data",  
"\_id" : "2",  
"\_score" : null, "\_source" : {  
"text" : "test rec 2",  
"myId" : 2  
},  
"sort" : [null]  
}, {  
"\_index" : "sorttest",  
"\_type" : "data",  
"\_id" : "3",  
"\_score" : null, "\_source" : {  
"text" : "test rec 3",  
"myId" : 3  
},  
"sort" : [null]  
} ]  
}  
}

---------- Query with sort on myId (working) -------------

curl -XGET 127.0.0.1:9200/sorttest/\_search?pretty=true -d '{  
"query" : {  
"match\_all":{}  
},  
"sort" : {  
"myId":"desc"  
}  
}';

{  
"took" : 74,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : null,  
"hits" : [ {  
"\_index" : "sorttest",  
"\_type" : "data",  
"\_id" : "3",  
"\_score" : null, "\_source" : {  
"text" : "test rec 3",  
"myId" : 3  
},  
"sort" : [3]  
}, {  
"\_index" : "sorttest",  
"\_type" : "data",  
"\_id" : "2",  
"\_score" : null, "\_source" : {  
"text" : "test rec 2",  
"myId" : 2  
},  
"sort" : [2]  
}, {  
"\_index" : "sorttest",  
"\_type" : "data",  
"\_id" : "1",  
"\_score" : null, "\_source" : {  
"text" : "test rec 1",  
"myId" : 1  
},  
"sort" : [1]  
} ]  
}  
}

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [October 13, 2011, 12:02pm UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586/2 "2011-10-13T12:02:11Z")

</div>

use \_uid

[http://groups.google.com/group/elasticsearch/browse\_thread/thread/b7568b6caa2ed55/](http://groups.google.com/group/elasticsearch/browse_thread/thread/b7568b6caa2ed55/)

On 13 Okt., 13:48, dmcclure [duane.mccl...@gmail.com](mailto:duane.mccl...@gmail.com) wrote:

> Just moved from 0.15.2 to 0.17.8 and appears that sorting on \_id no  
> longer works as expected. Have verified this from command line and in  
> a test case using the java apis.
> 
> Below are the results from two queries executed from command line, one  
> with sort on my own id (myId) and other with sort on \_id. Sort on \_id  
> does not work as expected but the other one does. Also, noticed that  
> the results for the sort on \_id have no values populated in the "sort"  
> output (as in "sort" : [null])
> 
> --------------- Data Setup ----------------
> 
> curl -XPUT '[http://localhost:9200/sorttest/'-d](http://localhost:9200/sorttest/'-d) '{  
> "index":{  
> "standard":{  
> "type":"standard"  
> }  
> }  
> }
> 
> }}';
> 
> curl -XPUT '[http://localhost:9200/sorttest/data/\_mapping'-d](http://localhost:9200/sorttest/data/_mapping'-d) '  
> {  
> "asset" : {  
> "properties" : {  
> "myId" : {"type" : "long"},  
> "text" : {"type" : "string", "index" : "analyzed",  
> "analyzer":"standard"}  
> }  
> }
> 
> }';
> 
> curl -XPUT '[http://localhost:9200/sorttest/data/1'-d](http://localhost:9200/sorttest/data/1'-d) '{  
> "text" : "test rec 1",  
> "myId" : 1
> 
> }';
> 
> curl -XPUT '[http://localhost:9200/sorttest/data/2'-d](http://localhost:9200/sorttest/data/2'-d) '{  
> "text" : "test rec 2",  
> "myId" : 2
> 
> }';
> 
> curl -XPUT '[http://localhost:9200/sorttest/data/3'-d](http://localhost:9200/sorttest/data/3'-d) '{  
> "text" : "test rec 3",  
> "myId" : 3
> 
> }';
> 
> ---------- Query with sort on \_id (not working, sort is [null] in  
> results) -------------
> 
> curl -XGET 127.0.0.1:9200/sorttest/\_search?pretty=true -d '{  
> "query" : {  
> "match\_all":{}  
> },  
> "sort" : {  
> "\_id":"desc"  
> }
> 
> }';
> 
> {  
> "took" : 78,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : null,  
> "hits" : [ {  
> "\_index" : "sorttest",  
> "\_type" : "data",  
> "\_id" : "1",  
> "\_score" : null, "\_source" : {  
> "text" : "test rec 1",  
> "myId" : 1},
> 
> ```
> "sort" : [null]
> 
> ```
> 
> \<======== ????, \_id values do not appear  
> }, {  
> "\_index" : "sorttest",  
> "\_type" : "data",  
> "\_id" : "2",  
> "\_score" : null, "\_source" : {  
> "text" : "test rec 2",  
> "myId" : 2},
> 
> ```
> "sort" : [null]
> }, {
> "_index" : "sorttest",
> "_type" : "data",
> "_id" : "3",
> "_score" : null, "_source" : {
> "text" : "test rec 3",
> "myId" : 3},
> 
> "sort" : [null]
> } ]
> 
> ```
> 
> }
> 
> }
> 
> ---------- Query with sort on myId (working) -------------
> 
> curl -XGET 127.0.0.1:9200/sorttest/\_search?pretty=true -d '{  
> "query" : {  
> "match\_all":{}  
> },  
> "sort" : {  
> "myId":"desc"  
> }
> 
> }';
> 
> {  
> "took" : 74,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : null,  
> "hits" : [ {  
> "\_index" : "sorttest",  
> "\_type" : "data",  
> "\_id" : "3",  
> "\_score" : null, "\_source" : {  
> "text" : "test rec 3",  
> "myId" : 3},
> 
> ```
> "sort" : [3]
> }, {
> "_index" : "sorttest",
> "_type" : "data",
> "_id" : "2",
> "_score" : null, "_source" : {
> "text" : "test rec 2",
> "myId" : 2},
> 
> "sort" : [2]
> }, {
> "_index" : "sorttest",
> "_type" : "data",
> "_id" : "1",
> "_score" : null, "_source" : {
> "text" : "test rec 1",
> "myId" : 1},
> 
> "sort" : [1]
> } ]
> 
> ```
> 
> }
> 
> }

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [October 13, 2011, 2:28pm UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586/3 "2011-10-13T14:28:14Z")

</div>

Hi

On Thu, 2011-10-13 at 04:48 -0700, dmcclure wrote:

> Just moved from 0.15.2 to 0.17.8 and appears that sorting on \_id no  
> longer works as expected. Have verified this from command line and in  
> a test case using the java apis.

As of version 0.16, the \_id field is no longer indexed by default:

> <https://github.com/elastic/elasticsearch/issues/868>
>
> In order to save memory usage (per shard), don't index \`\_id\` by default. No func…tionality is lost unless executing explicit search queries against \`\_id\` field (for example, using term query / filter). These can be replaced with the \`ids\` query/filter (which work without the need for \`\_id\` to be indexed, and work even faster).
> 
> To maintain backward compatibility (assuming the \`\_id\` specific queries can't be translated / no time to do it), the \`index.mapping.\_id.indexed\` setting should be set to \`true\`.
> 
> Note, the above flag should not be the one to use if wishing to index the \`\_id\` field on a clean index, instead, the \`\_id\` mapping can have \`index\` set to \`not\_analyzed\`.

You can turn set {\_id: { index: "not\_analyzed"}} in your mapping if you  
want to turn it back on.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

clint

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [October 13, 2011, 2:30pm UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586/4 "2011-10-13T14:30:16Z")

</div>

On Thu, 2011-10-13 at 05:02 -0700, Karussell wrote:

> use \_uid

\_uid includes the type, which may produce different results than  
expected

clint

---

<div class="post-metadata">

### Author: ![dmcclure1](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dmcclure1](https://discuss.elastic.co/u/dmcclure1)
#### Post date: [October 13, 2011, 8:15pm UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586/5 "2011-10-13T20:15:37Z")

</div>

Appreciate the responses, thanks.

On Oct 13, 10:30 am, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> On Thu, 2011-10-13 at 05:02 -0700, Karussell wrote:
> 
> > use \_uid
> 
> \_uid includes the type, which may produce different results than  
> expected
> 
> clint

---

<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, 3:52am UTC](https://discuss.elastic.co/t/sorting-on--id-in-0-17-8-does-not-appear-to-work/5586/6 "2017-07-06T03:52:01Z")

</div>


