#安装 Elasticsearch-head
count 指标
group 桶
工具 :
elesticsearch head
mysql 转换语法工具 : http://www.ischoolbar.com/EsParser/
1.去重
{ "size" : 0, "aggs" : { "distinct_colors" : { "cardinality" : { "field" : "去重的字段名" } } } }
2.聚合
根据颜色字段计算 每个桶下的个数
{ "size" : 0, "aggs" : { "popular_colors" : { "terms" : { "field" : "color" } } } }
3.先按性别分桶 然后再根据性别下查看有几重颜色 (去重)
{ "query": { "bool": { "should": [], "must_not": [], "must": [ { "range": { "createAt": { "gt": "2020-07-09T15:25:00.000+0800", "lt": "2020-07-09T15:25:00.200+0800" } } } ] } }, "sort": [], "aggs": { "all_brasname": { "terms": { "field": "brasname.keyword" }, "aggs": { "distinct_stbid": { "cardinality": { "field": "stbid.keyword" } } } } } }