Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created November 16, 2011 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickhoffman/1371224 to your computer and use it in GitHub Desktop.
Save nickhoffman/1371224 to your computer and use it in GitHub Desktop.
ElasticSearch: sorting on strings doesn't support the "missing" option
// Setup
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
{"ok":true,"_index":"test","_type":"tweets","_id":"1","_version":1}
{"ok":true,"_index":"test","_type":"tweets","_id":"2","_version":1}
{"ok":true,"_index":"test","_type":"tweets","_id":"3","_version":1}
// The first query, with the "missing" option, fails.
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[Z5lN30goQ0euwj3ce-OPrA][test][1]: SearchParseException[[test][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{ sort : [ { name : {order : \"asc\", missing: \"_last\"} } ] }\n]]]; nested: ElasticSearchIllegalArgumentException[Sorting on string type field does not support missing parameter]; }{[Z5lN30goQ0euwj3ce-OPrA][test][4]: SearchParseException[[test][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{ sort : [ { name : {order : \"asc\", missing: \"_last\"} } ] }\n]]]; nested: ElasticSearchIllegalArgumentException[Sorting on string type field does not support missing parameter]; }{[Z5lN30goQ0euwj3ce-OPrA][test][2]: SearchParseException[[test][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{ sort : [ { name : {order : \"asc\", missing: \"_last\"} } ] }\n]]]; nested: ElasticSearchIllegalArgumentException[Sorting on string type field does not support missing parameter]; }]",
"status" : 500
}
// The second query, without the "missing" option, works.
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : null,
"hits" : [ {
"_index" : "test",
"_type" : "tweets",
"_id" : "2",
"_score" : null, "_source" : { },
"sort" : [ null ]
}, {
"_index" : "test",
"_type" : "tweets",
"_id" : "3",
"_score" : null, "_source" : { name : "Goldbug" },
"sort" : [ "goldbug" ]
}, {
"_index" : "test",
"_type" : "tweets",
"_id" : "1",
"_score" : null, "_source" : { name : "Grimlock" },
"sort" : [ "grimlock" ]
} ]
}
}
curl -X DELETE 'localhost:9200/test'
curl -X PUT 'localhost:9200/test'
curl -X POST 'localhost:9200/test/tweets/1' -d '{ name : "Grimlock" }'
curl -X POST 'localhost:9200/test/tweets/2' -d '{ }'
curl -X POST 'localhost:9200/test/tweets/3' -d '{ name : "Goldbug" }'
sleep 1
curl 'localhost:9200/test/tweets/_search?pretty=true' -d '
{ sort : [ { name : {order : "asc", missing: "_last"} } ] }
'
curl 'localhost:9200/test/tweets/_search?pretty=true' -d '
{ sort : [ { name : {order : "asc"} } ] }
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment