Bucket Script pipeline aggregation is not working with filter aggregation

Fails with
class org.elasticsearch.search.aggregations.bucket.filter.InternalFilter cannot be cast to class org.elasticsearch.search.aggregations.InternalMultiBucketAggregation

Should it be that restrictive? For instance it works with Filters aggregation

Even though it is a single bucket it is still very useful to be able to perform calculation within it. Particularly if I do it in a multilevel aggregation which starts from filter agg and then may have couple of levels of say range aggs and I want consistent pipeline aggs on every level

Could you please show what the actual query is you are trying to run? The error alone isn't sufficient to understand what is occurring.

POST test3/_doc/
{
    "type" : 1,
    "discounted" : 1,
    "sold" : 1
}
POST test3/_doc/
{
    "type" : 1,
    "discounted" : 1,
    "sold" : 0
}
POST test3/_doc/
{
    "type" : 1,
    "discounted" : 0,
    "sold" : 0
}


POST test3/_search
{
  "size": 0,
  "aggs": {
    "type1": {
      "filter": {
        "term": {
          "type": 1
        }
      },
      "aggs": {
        "discounted": {
          "sum": {
            "field": "discounted"
          }
        },
        "sold": {
          "sum": {
            "field": "sold"
          }
        },
        "discounted_sold": {
          "bucket_script": {
            "buckets_path": {
              "discounted": "discounted",
              "sold": "sold"
            },
            "script": "params.sold  / params.discounted"
          }
        }
      }
    }
  }
}
{
  "error": {
    "root_cause": [],
    "type": "search_phase_execution_exception",
    "reason": "",
    "phase": "fetch",
    "grouped": true,
    "failed_shards": [],
    "caused_by": {
      "type": "class_cast_exception",
      "reason": "class org.elasticsearch.search.aggregations.bucket.filter.InternalFilter cannot be cast to class org.elasticsearch.search.aggregations.InternalMultiBucketAggregation (org.elasticsearch.search.aggregations.bucket.filter.InternalFilter and org.elasticsearch.search.aggregations.InternalMultiBucketAggregation are in unnamed module of loader 'app')"
    }
  },
  "status": 500
}

@rjernst please see fully working example in my post above

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.