
类似 select couponTypeId,counterCode,count(*) from table group by couponTypeId,counterCode
下面是是单条件聚合
POST coupon_statistics_record/_search
{ "aggs": { "group_by_couponTypeId": { "terms": {"field": "couponTypeId.keyword"} } } } 1 helloZwq Jun 4, 2020 aggs 下面再写一个 agg 就好了 |
2 rqxiao OP @helloZwq 试了下可以的 POST coupon_statistics_record/_search { "aggs": { "group_by_couponTypeId": { "terms": { "field": "couponTypeId.keyword" } }, "group_by_counterCode": { "terms": { "field": "counterCode.keyword" } } } } |
3 rqxiao OP @helloZwq 还想请问下 把第二个聚合的字段改成了时间,想用时间( yyyy--MM )来分组,这个 "format": "yyyy-MM"没有生效的样子 POST coupon_statistics_record/_search { "aggs": { "group_by_couponTypeId": { "terms": { "field": "couponTypeId.keyword" }, "aggs": { "group_by_creatime": { "terms": { "field": "createTime", "format": "yyyy-MM" } } } } } } |
4 rqxiao OP 聚合的时候就让 同一个月的在一组不知道这样可以不可以呢 |
5 wangyanrui Jun 4, 2020 subAgg 不能解决吗? 还是我太菜了没有读懂楼主的问题! |
6 helloZwq Jun 4, 2020 按月划分的话有直接的 api "aggs": { "NAME": { "date_histogram": { "field": "date", "interval": "month" } } } |
7 rqxiao OP @helloZwq 不好意思,还想请教下 如果是对日期类型进行 月份级别的统计这样写 "range" : { "createTime" : { "gte": "2020-05", "lte": "2020-05", "format" : "yyyy-MM" } } 会默认为 2020-05-01 00:00:00 2020-05-01 23:59:59 来统计是吗 要通过日统计这样才能完成月份级别的统计吗 "range" : { "createTime": { "gte": "2020-05-01", "lte": "2020-05-31", "format":"yyyy-MM-dd" } } |