Does the Location of a Filter in a Query Matter?

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?

It's smart enough to run the filter first :slight_smile:

1 Like

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