Open
Description
Possibly related to #42196
Here is a complete test case to show the problem. Tested on ES 7.0.1
PUT movfn_test
POST movfn_test/_doc/1
{
"timestamp_utc": "2019-05-01",
"foo": 1
}
POST movfn_test/_doc/3
{
"timestamp_utc": "2019-05-03",
"foo": 3
}
POST movfn_test/_search
{
"size": 0,
"aggs": {
"days": {
"date_histogram": {
"min_doc_count": 0,
"field": "timestamp_utc",
"interval": "1d"
},
"aggs": {
"curr_foo": { "avg": {"field": "foo" }},
"prev_foo": {
"moving_fn": {
"buckets_path": "curr_foo", "window": 1,
"script": "MovingFunctions.sum(values)",
"gap_policy": "skip"
}}
}}
},
"query": {
"match_all": {}
}
}
Returns
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"days" : {
"buckets" : [
{
"key_as_string" : "2019-05-01T00:00:00.000Z",
"key" : 1556668800000,
"doc_count" : 1,
"curr_foo" : {
"value" : 1.0
},
"prev_foo" : {
"value" : 0.0
}
},
{
"key_as_string" : "2019-05-02T00:00:00.000Z",
"key" : 1556755200000,
"doc_count" : 0,
"curr_foo" : {
"value" : null
}
},
{
"key_as_string" : "2019-05-03T00:00:00.000Z",
"key" : 1556841600000,
"doc_count" : 1,
"curr_foo" : {
"value" : 3.0
},
"prev_foo" : {
"value" : 1.0
}
}
]
}
}
}
I expect prev_foo
on day 03
to be null
and not 1.0
.
That is, I don't think gap_policy: skip
means to extend the window back until a value is found. The window is 1 and I expect that to be honored. Here skip
should not do anything. In the case of the fn being unweightedAvg
or similar, I expect skip to mean that "missing" value should not be included in the set to be averaged.