Hi,
I'm trying to use the bucket selector aggregation to filter out some unwanted buckets from my response, buckets that I'm not interested in (but are used in the calculation - moving avg). My main aggregation is a date_histogram and therefore the _key
is a date. I have tried the following without success:
"_m_pipeline": {
"date_histogram": {
"field": "date",
"interval": "month"
},
"aggs": {
"_m_sum": {
"sum": {
"field": "value"
}
},
... <other aggregations here> ...
"_m_data_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"bucket_key": "_key"
},
"script": "params.bucket_key < 1491004800000L" // This number is equivalent to 2017-04-01 00:00:00
}
}
The result I get is:
{
"error": {
"root_cause": [],
"type": "reduce_search_phase_exception",
"reason": "[reduce] ",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
"type": "aggregation_execution_exception",
"reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.joda.time.DateTime"
}
},
"status": 503
}
The main idea of my query is to get a monthly moving average of window 12. In order to calculate this, I need at least 12 months of data in my histogram, but I am only interested in the latest value of the moving average, therefore I would like to discard (server side) the excess data for post processing.
Any ideas if this is possible? And how?
Thank you!