简体   繁体   中英

How do I make sure null or missing fields comes first during sort on that field in Elastic Search

I am writing a Java client for elastic search. How do make sure my null or missing field comes always first when sorting using that field.

Please make sure you set _first for the "missing" in your search query

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

In java

FieldSortBuilder sorter = new FieldSortBuilder("price");
sorter.missing("_first");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM