排序默认只能按两个字段排序:_count 和 _key
如果想按二次聚合结果中的字段排序语法如下:
GET how2java/product/_search //求每个地方商品数量,并按平均价格从高往低排序
{ "size": 0, "aggs": { "place_bucket": { "terms": { "field": "place.keyword", "size": 10, "order": { "second_bucket.avg": "desc" //二次聚合名加. ,多层结果 中间连接用 < } }, "aggs": { "second_bucket": { "stats": { "field": "price" } } } } } }
结果
标签:聚合,bucket,elasticsearch,place,排序,size From: https://www.cnblogs.com/wscw/p/16790072.html