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 '{
"index":{
"standard":{
"type":"standard"
}
}
}
}}';
curl -XPUT '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 '{
"text" : "test rec 1",
"myId" : 1
}';
curl -XPUT 'http://localhost:9200/sorttest/data/2' -d '{
"text" : "test rec 2",
"myId" : 2
}';
curl -XPUT '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 ]
} ]
}
}