elasticsearch/elasticsearch — Issue #1529: Sort: Support "missing" for string types
Author: erickt
Created: 2011-12-09 02:26:18+00:00
State: open

Sorting on documents that are missing a key would be very helpful, partially matching the api for sorting numerical values. For example:

{
"sort" : [
{ "user" : {"missing" : "_last"} },
],
"query" : {
"term" : { "user" : "kimchy" }
}

{
"sort" : [
{ "user" : {"missing" : "_last"} },
],
"query" : {
"term" : { "user" : "kimchy" }
}

Unfortunately we can't use this pattern for custom values. To support that, we'll need a sub-object:

{
"sort" : [
{ "user" : {"missing" : { "order": "_first"} } },
],
"query" : {
"term" : { "user" : "kimchy" }
}

{
"sort" : [
{ "user" : {"missing" : { "order": "_last"} } },
],
"query" : {
"term" : { "user" : "kimchy" }
}

{
"sort" : [
{ "user" : {"missing" : { "value": "nobody"} } },
],
"query" : {
"term" : { "user" : "kimchy" }
}