# Unable to apply filter on serial\_diff aggregation

**URL:** <https://discuss.elastic.co/t/unable-to-apply-filter-on-serial-diff-aggregation/113203>\
**Category:** Elasticsearch\
**Created:** [December 26, 2017, 11:11am UTC](https://discuss.elastic.co/t/unable-to-apply-filter-on-serial-diff-aggregation/113203 "2017-12-26T11:11:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexer338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hexer338/32/47413_2.png) [@hexer338](https://discuss.elastic.co/u/hexer338)\
**Post date:** [December 26, 2017, 11:11am UTC](https://discuss.elastic.co/t/unable-to-apply-filter-on-serial-diff-aggregation/113203/1 "2017-12-26T11:11:45Z")

</div>

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:

```auto
{
   "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:

```auto
{
   "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.

---

<div class="post-metadata">

**Author:** ![hexer338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hexer338/32/47413_2.png) [@hexer338](https://discuss.elastic.co/u/hexer338)\
**Post date:** [December 28, 2017, 7:48am UTC](https://discuss.elastic.co/t/unable-to-apply-filter-on-serial-diff-aggregation/113203/2 "2017-12-28T07:48:59Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 25, 2018, 7:49am UTC](https://discuss.elastic.co/t/unable-to-apply-filter-on-serial-diff-aggregation/113203/3 "2018-01-25T07:49:29Z")

</div>

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