【ES】學習11-多桶排序
阿新 • • 發佈:2017-06-16
nbsp order key actions color 字符串 efi 結果 literal
聚合結果的排序
默認:桶會根據 doc_count
降序排列。
內置排序:
設置按doc_count升序排序:註意order,_count
GET /cars/transactions/_search { "size" : 0, "aggs" : { "colors" : { "terms" : { "field" : "color", "order": { "_count" : "asc" } } } } }
其他排序關鍵字:
_count
按文檔數排序。對 terms
、 histogram
、 date_histogram
有效。
_term
按詞項的字符串值的字母順序排序。只在 terms
內使用。
_key
按每個桶的鍵值數值排序(理論上與 _term
類似)。 只在 histogram
和date_histogram
內使用。
按度量排序:根據字段名稱引用度量即可
GET /cars/transactions/_search { "size" : 0, "aggs" : { "colors" : { "terms" : {"field" : "color", "order": { "avg_price" : "asc" } }, "aggs": { "avg_price": { "avg": {"field": "price"} } } } } }
多值度量使用點式路徑:extended_stats度量輸出多個度量值
GET /cars/transactions/_search {"size" : 0, "aggs" : { "colors" : { "terms" : { "field" : "color", "order": { "stats.variance" : "asc" } }, "aggs": { "stats": { "extended_stats": {"field": "price"} } } } } }
【ES】學習11-多桶排序