# Query performance- filter aggregation with the same filter improve performance drastically

**URL:** <https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618>\
**Category:** Elasticsearch\
**Created:** [July 26, 2021, 11:19am UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618 "2021-07-26T11:19:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexs1](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@alexs1](https://discuss.elastic.co/u/alexs1)\
**Post date:** [July 26, 2021, 11:19am UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618/1 "2021-07-26T11:19:36Z")

</div>

Can anyone explain why the left (pseudo) query runs above 5s the while the right part in 30ms?

The filters in the example below, are identical (aggs/ query filters).

isn't the aggregation part suppose to run on filtered data? (result value is the same)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/0/2043b8b501cb825ccf6eef1d2111fddf4a78f51c.jpeg)

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 26, 2021, 12:26pm UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618/2 "2021-07-26T12:26:54Z")

</div>

Which Elasticsearch version are you running on?

Also please make sure that the [request cache](https://www.elastic.co/guide/en/elasticsearch/reference/7.13/shard-request-cache.html) does not skew your calculations and try both queries with that cache disabled.

---

<div class="post-metadata">

**Author:** ![alexs1](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@alexs1](https://discuss.elastic.co/u/alexs1)\
**Post date:** [July 26, 2021, 12:33pm UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618/3 "2021-07-26T12:33:41Z")

</div>

thanks @spinscale

version: 7.13.2  
added request\_cache=false to both ..

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 26, 2021, 1:19pm UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618/4 "2021-07-26T13:19:48Z")

</div>

I think you are hitting a bug I caused in 7.13. This is the fix, coming in 7.14: [https://github.com/elastic/elasticsearch/pull/74260](https://github.com/elastic/elasticsearch/pull/74260)

When we found the bug I scrambled to get an emergency "off switch" into the system for 7.13.2 so you can try it: [https://github.com/elastic/elasticsearch/pull/73620](https://github.com/elastic/elasticsearch/pull/73620)

Sorry for the trouble!

---

<div class="post-metadata">

**Author:** ![ustrauss](https://avatars.discourse-cdn.com/v4/letter/u/f0a364/32.png) [@ustrauss](https://discuss.elastic.co/u/ustrauss)\
**Post date:** [July 26, 2021, 1:47pm UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618/6 "2021-07-26T13:47:12Z")

</div>

We hit the same bug on version 7.13.2, it took us 2 weeks to understand where it's coming from and how to work around it. Due to high latency, it was crashing the cluster on specific reports that were generated by users.

---

<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:** [August 23, 2021, 1:47pm UTC](https://discuss.elastic.co/t/query-performance-filter-aggregation-with-the-same-filter-improve-performance-drastically/279618/7 "2021-08-23T13:47:57Z")

</div>

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