# Does the order of filters matter?

**URL:** <https://discuss.elastic.co/t/does-the-order-of-filters-matter/81489>\
**Category:** Elasticsearch\
**Created:** [April 6, 2017, 2:48pm UTC](https://discuss.elastic.co/t/does-the-order-of-filters-matter/81489 "2017-04-06T14:48:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cju](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@cju](https://discuss.elastic.co/u/cju)\
**Post date:** [April 6, 2017, 2:48pm UTC](https://discuss.elastic.co/t/does-the-order-of-filters-matter/81489/1 "2017-04-06T14:48:18Z")

</div>

Hello,

I have a query like this one :

```
     query:
       filter:
         bool:
             must:
                 - range:
                     from date to date
                 - bool:
                     - should:
                         - term
                         - term
                 - bool:
                     - should:
                         - term
                         - term
                         - ****

```

I don't understand how filters are performed.  
If the last bool filter is the most restrictive, should I place it in first position ?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 8, 2017, 11:25pm UTC](https://discuss.elastic.co/t/does-the-order-of-filters-matter/81489/2 "2017-04-08T23:25:59Z")

</div>

ES applies logic to reformat queries to be as optimal as it can be. It shouldn't matter too much, as long as you are running a modern release (the newer the better!).

---

<div class="post-metadata">

**Author:** ![cju](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@cju](https://discuss.elastic.co/u/cju)\
**Post date:** [April 10, 2017, 12:00pm UTC](https://discuss.elastic.co/t/does-the-order-of-filters-matter/81489/3 "2017-04-10T12:00:28Z")

</div>

Ok thanks for your answer

---

<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:** [May 8, 2017, 12:06pm UTC](https://discuss.elastic.co/t/does-the-order-of-filters-matter/81489/4 "2017-05-08T12:06:04Z")

</div>

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