我要统计最近一周的每天货品的个数。也就是我查询需要返回哪一天2020-07-18,种类,数量这三个字段,dsl怎么写呢??
比如按天统计
searchdsl := map[string]interface{}{
"query": map[string]interface{}{
"bool": map [string]interface{}{ "filter": map[string]interface{}{
"bool": map[string]interface{}{
"must": map[string]interface{}{
"range": map[string]interface{}{
"你的时间": map[string]interface{}{
"gte": "2020-07-01 00:00:00",
"lte": "2020-07-20 00:00:00"
},
},
},
},
},
},
},
"size": 0,
"aggs": map[string]interface{}{
"group": map[string]interface{}{
"date_histogram": map[string]interface{}{
"field": "你的字段",
"calendar_interval": "day", //按天统计
//"time_zone":"+08:00",
"format": "yyyy-MM-dd",
"min_doc_count": 0,
},
"aggs": map[string]interface{}{
"group": map[string]interface{}{
"terms": map[string]interface{}{
"field": "你的第二个维度统计",
},
},
},
},
},
}
核心:
"aggs": {
"xxxxxx": {
"date_histogram": {
"field": "createdAt",
"interval": "day",
"format": "yyyy-MM-dd",
"time_zone": "+08:00"
}
}
},
配合多维字段统计