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
原文地址:https://www.cnblogs.com/iiiiiher/p/10190949.html
时间: 2024-11-09 02:45:27