# Which filter query is good as per performance wise?

**URL:** <https://discuss.elastic.co/t/which-filter-query-is-good-as-per-performance-wise/140078>\
**Category:** Elasticsearch\
**Created:** [July 16, 2018, 4:27am UTC](https://discuss.elastic.co/t/which-filter-query-is-good-as-per-performance-wise/140078 "2018-07-16T04:27:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [July 17, 2018, 1:36pm UTC](https://discuss.elastic.co/t/which-filter-query-is-good-as-per-performance-wise/140078/2 "2018-07-17T13:36:10Z")

</div>

It's hard to give general performance advice. It's always best to test how specific queries perform on your documents, like you have done already. But keep in mind that measuring the performance of a single query executed once may not be representative.

Having said that - let me try to give you some pointers.

In general, if you do not care about a score, using a `filter` is better than using a bool query's `must` or `should` clause. Elasticsearch will not have to calculate a score for filters, so that will be faster. Additionally, some filters can be cached by Elasticsearch, which can have a significant positive impact on your cluster. So, for these two reasons - I would not go with your first query.

With regard to your queries 2 and 3: the `category` field is mapped as type `short`. Do you really need that field to be a number? Are you running mathematical operations like sum or average aggregations on that field? If not, it may be better to map that field as type `keyword`. Then, query 3 is going to be the most performant. As it is, with `category` mapped as type `short`, query 2 may be more performant, as numeric types are optimized for `range` queries.

You can find more general advice in our documentation here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-search-speed.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-search-speed.html)

---

_[View the full topic](https://discuss.elastic.co/t/which-filter-query-is-good-as-per-performance-wise/140078)._
