# Is filteredQuery cached in any way?

**URL:** <https://discuss.elastic.co/t/is-filteredquery-cached-in-any-way/62668>\
**Category:** Elasticsearch\
**Created:** [October 10, 2016, 9:28pm UTC](https://discuss.elastic.co/t/is-filteredquery-cached-in-any-way/62668 "2016-10-10T21:28:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EuclideanSearch](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@EuclideanSearch](https://discuss.elastic.co/u/EuclideanSearch)\
**Post date:** [October 10, 2016, 9:28pm UTC](https://discuss.elastic.co/t/is-filteredquery-cached-in-any-way/62668/1 "2016-10-10T21:28:22Z")

</div>

I am using a filteredQuery and I was wondering whether it does any caching of either the interior query or the filter. For example if I do (in java) QueryBuilders.filteredQuery(query, filterBuilder) is the result of the filter applied to the query cached (or is anything cached in that scenario)?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 11, 2016, 12:07pm UTC](https://discuss.elastic.co/t/is-filteredquery-cached-in-any-way/62668/2 "2016-10-11T12:07:26Z")

</div>

Hi,

this depends a bit on the version of ES you are using and also on the type of query that is wrapped as a filter. As a general guideline most "leaf filters" (those directly targeting a field in your documents) are cached in 1.x with some noteable exceptions described [here](https://www.elastic.co/guide/en/elasticsearch/guide/1.x/filter-caching.html). In 2.x the caching behaviour is more automatic to avoid overcaching. See this [blog post](https://www.elastic.co/blog/better-query-execution-coming-elasticsearch-2-0) for some detailed explanations.

---

<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:** [July 5, 2017, 10:13pm UTC](https://discuss.elastic.co/t/is-filteredquery-cached-in-any-way/62668/3 "2017-07-05T22:13:26Z")

</div>


