Sorting of aggregated results
Default: Buckets are sorted according to doc_count
descending order.
Built-in sorting:
Set sort by Doc_count ascending: note order,_count
get/cars/transactions/_search{"size":0, "Aggs" : { "Colors" : { "Terms" : { "Field":"Color", "Order": { "_count":"ASC" } } } }}
Other sort keywords:
_count
Sort by number of documents. Yes terms
, histogram
and date_histogram
effective.
_term
Sorts the alphabetical order of the string values of the word items. Use only terms
inside.
_key
Sort by the values of the key values for each bucket (theoretically and _term
similarly). Used only in histogram
and date_histogram
within.
Sort by measure: reference a metric based on the field name
get/cars/transactions/_search{"size":0, "Aggs" : { "Colors" : { "Terms" : { "Field":"Color", "Order": { "Avg_price":"ASC" } }, "Aggs": { "Avg_price": { "avg": {"Field":" Price"} } } } }}
Multi-value measures use point paths: extended_stats measures to output multiple measures
get/cars/transactions/_search{"size":0, "Aggs" : { "Colors" : { "Terms" : { "Field":"Color", "Order": { "stats.variance":"ASC" } }, "Aggs": { "Stats": { "Extended_stats": {"Field":" Price"} } } } }}
"ES" Learning 11-multi-barrel sorting