按文档计数排序
使用_count来引用每组聚合的文档计数进行排序
{"size": 0,"aggs": {"group_city": {"terms": {"field": "city","order": { //按照文档计数进行升序排列 "_count": "asc"}},"aggs": {"my_avg": {"avg": { //使用价格平均值作为聚合指标 "field": "price","missing": 200}}}}}
}
按聚合指标排序
按照每个组聚合后的指标值进行排序
{"size": 0,"aggs": {"group_city": {"terms": {"field": "city","order": { //按照聚合指标进行升序排列 "my_avg": "asc"}},"aggs": {"my_avg": { //定义聚合指标 "avg": {"field": "price","missing": 200}}}}}
}
按分组key排序
每个分组的组名称排序
{"size": 0,"aggs": {"group_city": {"terms": {"field": "city","order": { //按照分组key的自然顺序升序排列 "_key": "asc"}},"aggs": {"my_avg": { //定义聚合指标 "avg": {"field": "price","missing": 200}}}}}
}