Closed
Description
Here is a simple and complete case. I tested against ES 7.0.1
PUT bucket_scipt_test
POST bucket_scipt_test/_doc/1
{
"timestamp_utc": "2019-05-01",
"foo": 1
}
POST bucket_scipt_test/_doc/3
{
"timestamp_utc": "2019-05-03",
"foo": 3
}
POST bucket_scipt_test/_search
{
"size": 0,
"aggs": {
"days": {
"date_histogram": {
"min_doc_count": 0,
"field": "timestamp_utc",
"interval": "1d"
},
"aggs": {
"foo_script": {
"bucket_script": {
"buckets_path": "_count",
"script": "1"
}},
"copy": {
"bucket_script": {
"buckets_path": {"foo":"foo_script"},
"script": "params.foo",
"gap_policy": "insert_zeros"
}},
"sum": {
"cumulative_sum": {
"buckets_path": "foo_script"
}}
}}
},
"query": {
"match_all": {}
}
}
And the results I see from the search are
{
"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,
"foo_script" : {
"value" : 1.0
},
"copy" : {
"value" : 1.0
},
"sum" : {
"value" : 1.0
}
},
{
"key_as_string" : "2019-05-02T00:00:00.000Z",
"key" : 1556755200000,
"doc_count" : 0,
"foo_script" : {
"value" : 1.0
},
"copy" : {
"value" : 0.0
},
"sum" : {
"value" : 1.0
}
},
{
"key_as_string" : "2019-05-03T00:00:00.000Z",
"key" : 1556841600000,
"doc_count" : 1,
"foo_script" : {
"value" : 1.0
},
"copy" : {
"value" : 1.0
},
"sum" : {
"value" : 2.0
}
}
]
}
}
}
The problem I see is that gap_policy
can only be insert_zeros or skip. But with a bucket_script
, I really want the script to just run as normal, even when the doc_count in the bucket is zero.
Specifically, I expect the "copy.value" in the second bucket to be 1.0 and the "sum.value" to be 2.0. In the third bucket, I expect the "sum.value" to be 3.0.
Thank you for your consideration.