高峰只对攀登它而不是仰望它的人来说才有真正意义。

如何让moving_avg移动平均函计算时包括数据值为0的日期

Elasticsearch | 作者 hjchyp | 发布于2019年10月08日 | 阅读数:1830

代码如下,先聚合了每天的日期,然后再用移动平均计算了7天的平均值
{
"size": 0,
"aggs": {
"my_date_histo": {
"date_histogram": {
"field": "created_at",
"interval": "day"
},
"aggs": {
"the_count": {
"value_count": {
"field": "id"
}
},
"the_movavg":{
"moving_avg": {
"buckets_path": "the_count",
"window":7
}
}
}
}
}
}

这个时候,因为10月2日和3日没有数据,所以the_count那一项是0,但是the_movavg那一项也是0,如何让这个函数也计算带0的数据
{
"key_as_string" : "2019-09-30T00:00:00.000Z",
"key" : 1569801600000,
"doc_count" : 20,
"the_count" : {
"value" : 20
},
"the_movavg" : {
"value" : 35.857142857142854
}
},
{
"key_as_string" : "2019-10-01T00:00:00.000Z",
"key" : 1569888000000,
"doc_count" : 6,
"the_count" : {
"value" : 6
},
"the_movavg" : {
"value" : 31.857142857142858
}
},
{
"key_as_string" : "2019-10-02T00:00:00.000Z",
"key" : 1569974400000,
"doc_count" : 0,
"the_count" : {
"value" : 0
}
},
{
"key_as_string" : "2019-10-03T00:00:00.000Z",
"key" : 1570060800000,
"doc_count" : 0,
"the_count" : {
"value" : 0
}
},
{
"key_as_string" : "2019-10-04T00:00:00.000Z",
"key" : 1570147200000,
"doc_count" : 34,
"the_count" : {
"value" : 34
},
"the_movavg" : {
"value" : 25.857142857142858
}
},
已邀请:

要回复问题请先登录注册