Hi,
I am trying to use bucket_script aggregations inside a filter aggregation.
My query looks like this (I used count for simplicity in this example, but actual bucket script that I need is more complicated, so I do need a bucket_script)
"aggs": {
"filt": {
"filter": {
"bool": {
"should": [{
"match": {
"age": "24"
}}]
}
},
"aggs": {
"bucket_agg": {
"bucket_script": {
"buckets_path": {
"tc": "_count"
},
"script": "params.tc"
}
}
}
}
}
I get an error from Elasticsearch saying
{
"error": {
"root_cause": ,
"type": "search_phase_execution_exception",
"reason": "",
"phase": "fetch",
"grouped": true,
"failed_shards": ,
"caused_by": {
"type": "class_cast_exception",
"reason": "org.elasticsearch.search.aggregations.bucket.filter.InternalFilter cannot be cast to org.elasticsearch.search.aggregations.InternalMultiBucketAggregation"
}
},
"status": 503
}
However, when I wrap up the bucket script aggregation inside another aggregation, terms aggregation for example, it works
Query
"aggs": { "filt": { "filter": { "bool": { "should": [{ "match": { "age": "24" }}] } }, "aggs": { "name": { "terms": { "field": "name" }, "aggs": { "bucket_agg": { "bucket_script": { "buckets_path": { "tc": "_count" }, "script": "params.tc" } } } } } } }
Is there a reason why a bucket directly under a filter is not supported and is there a way to work around this?
Thank you,
Gevorg