Unable to apply filter on serial_diff aggregation


(Ravi Teja Meka) #1

Hi, If a filter or filters aggregation is applied above serial_diff aggregation, Elasticsearch is returning error.

Elasticsearch version: v5.6.4

Please find below ES query:

{
   "size": 0,
   "aggs": {
      "years": {
         "date_histogram": {
            "field": "order_date",
            "interval": "year"
         },
         "aggs": {
            "total_sales": {
               "sum": {
                  "field": "sales"
               }
            },
            "in_california": {
               "filter": {
                  "term": {
                     "state": "california"
                  }
               },
               "aggs": {
                  "total_sales": {
                     "sum": {
                        "field": "sales"
                     }
                  },
                  "__serial_diff__": {
                     "serial_diff": {
                        "gap_policy": "insert_zeros",
                        "buckets_path": "total_sales"
                     }
                  }
               }
            }
         }
      }
   }
}

This is the error that is being returned:

{
   "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
}{
   "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
}

The use case is: I want total_sales of all states, total_sales_of_california and increase in total_sales_of_california from previous year.


(Ravi Teja Meka) #2

Hi,
Can anyone help me with above query ?

I cant find any issue corresponding to above topic in elasticsearch repository.

If this is expected behaviour, can you suggest an alternate query for the requirement ?

Thanks in advance :slight_smile:


(system) #3

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