# Does the Location of a Filter in a Query Matter?

**URL:** <https://discuss.elastic.co/t/does-the-location-of-a-filter-in-a-query-matter/94601>\
**Category:** Elasticsearch\
**Created:** [July 26, 2017, 9:02am UTC](https://discuss.elastic.co/t/does-the-location-of-a-filter-in-a-query-matter/94601 "2017-07-26T09:02:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ong/32/40766_2.png) [@Ong](https://discuss.elastic.co/u/Ong)\
**Post date:** [July 26, 2017, 9:02am UTC](https://discuss.elastic.co/t/does-the-location-of-a-filter-in-a-query-matter/94601/1 "2017-07-26T09:02:12Z")

</div>

In an Elasticsearch query, does it matter where we place the filter?

The examples I come across put filter after the query. Like the following:

```
GET _search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "text": "quick brown fox"
        }
      },
      "filter": {
        "term": {
          "status": "published"
        }
      }
    }
  }
}

```

If the filter is put first above the "must match" sub body, does this affect how Elasticsearch executes the query i.e. Does it run the filter first then run the query on the subset of documents?

Or is there no difference at all?

---

<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:** [July 26, 2017, 9:13am UTC](https://discuss.elastic.co/t/does-the-location-of-a-filter-in-a-query-matter/94601/2 "2017-07-26T09:13:37Z")

</div>

It's smart enough to run the filter first 🙂

---

<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, 2017, 9:13am UTC](https://discuss.elastic.co/t/does-the-location-of-a-filter-in-a-query-matter/94601/3 "2017-08-23T09:13:54Z")

</div>

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