First analysis Hibernate Search and sorting FullTextQuery.setSort( ) is the main entry point. Sort is the Lucene object. DistanceSortField is used for spatial:
- Coordinates or lat, long
- fieldname
- reverse
Lucene sort Default: RELEVANCE, INDEXORDER Otherwise Sort is a List of SortField:
- defaults like score and docid
- field name
- field type (with sorting type - up to custom Comparator)
- reverse or not
- missingValue (for string: first or last ; for numeric ; excluded others)
- FieldComparatorSource
subclasses:
- SortedNumericSortField: (for numeric multi values, compare with the min or max value)
- SortedSetSortField: (for multi values, compare with the min or max value)
Elasticsearch sort https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html => JSON structure
{
"sort" : [
{ "post_date" : {"order" : "asc"}},
"user",
{ "name" : "desc" },
{ "age" : "desc" },
"_score"
],
"query" : {
"term" : { "user" : "kimchy" }
}
}
_doc is the most efficient sort mode for multi values: min, max, sum, avg, median Sort on nested
"sort" : [
{
"offer.price" : {
"mode" : "avg",
"order" : "asc",
"nested_path" : "offer",
"nested_filter" : {
"term" : { "offer.color" : "blue" }
}
}
}
]
nested_path seems a constraint that could be guessed? nested_filter allows to filter out the nested elements filtered by Missing value _last, _first, custom value (used as the value used to sort when the field is missing) Ignoring unmapped field { "sort" : [ { "price" : {"unmapped_type" : "long"} }, ], "query" : { "term" : { "user" : "kimchy" } } } pretends the documents have a field type of long and the field is always empty in the documents. Geo distance sorting distance_type: sloppy_arc, arc, plane unit: km point as lat, long or geohash Multiple geo points can be passed as an array containing any geo_point format The final distance for a document will then be min/max/avg (defined via mode) distance of all points contained in the document to all points given in the sort request. sort by script track score even if not sorted by score "track_scores": true |