例子1 统计1,有唱歌兴趣的 2,按年龄分组 3,求每组平均年龄 4,按平均年龄降序排序
sql转为dsl例子
# 每种型号车的颜色数 > 1的
SELECT model,COUNT(DISTINCT color) color_count FROM cars
GROUP BY model
HAVING color_count > 1
ORDER BY color_count desc
LIMIT 2;
GET cars/_search
{"size": 0,"aggs": {"models": {"terms": {"field": "model.keyword"},"aggs": {"color_count": {"cardinality": {"field": "color.keyword"}},"color_count_filter": {"bucket_selector": {"buckets_path": {"colorCount": "color_count"},"script": "params.colorCount>1"}},"color_count_sort": {"bucket_sort": {"sort": {"color_count": "desc"},"size": 2}}}}}
}
23个有用的elasticsearch例子
https://cloud.tencent.com/developer/article/1367657