# Filter performance difference (Bool vs Terms)

**URL:** <https://discuss.elastic.co/t/filter-performance-difference-bool-vs-terms/59928>\
**Category:** Elasticsearch\
**Created:** [September 6, 2016, 10:40pm UTC](https://discuss.elastic.co/t/filter-performance-difference-bool-vs-terms/59928 "2016-09-06T22:40:46Z")\
**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:** [September 6, 2016, 10:40pm UTC](https://discuss.elastic.co/t/filter-performance-difference-bool-vs-terms/59928/1 "2016-09-06T22:40:46Z")

</div>

I have a terms filter (over multiple fields) and an equivalent boolean query; but the terms query is faster. Is some optimization performed when the terms filter is applied (which thereby allows it to perform better than the equivalent boolean query)?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [September 6, 2016, 11:23pm UTC](https://discuss.elastic.co/t/filter-performance-difference-bool-vs-terms/59928/2 "2016-09-06T23:23:05Z")

</div>

Yep 🙂 You can read more about it here: [https://www.elastic.co/guide/en/elasticsearch/guide/current/filter-caching.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/filter-caching.html)

Generally, filters are executed in a "non-scoring" mode which gives them two main performance advantages. Firstly, they can omit the actual scoring of the document. Scoring a doc is relatively quick (the summation of a bunch of multiplications), but even 1ns for a billion documents is 1 second of computation.

Secondly, non-scoring filters can be cached, meaning subsequent executions of the filter clause can leverage the cache instead of hitting the various data-structures.

Where possible, we encourage people to convert queries =\> filters for better performance (assuming you don't need the scoring aspect)

---

<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:22pm UTC](https://discuss.elastic.co/t/filter-performance-difference-bool-vs-terms/59928/3 "2017-07-05T22:22:12Z")

</div>


