Filter syntax deprecated?


(Dorjee Dhondup) #1

I have seen two ways the filter is used. Is 1 still valid or deprecated?

#1
GET index/_search
{
"filter":{
"exists": {
"field": "FIELD_NAME"
}
}
}

#2

{
  "query": {
    "bool": {
      "filter": {
        "exists": {
          "field": "FIELD_NAME"
        }
      }
    }
  }
}

(Zachary Tong) #2

They are two different things. Option 1) is indeed deprecated, and has been replaced with the post_filter syntax: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html

But post-filtering is executed after the query clause finishes, as a means to do an additional filtering step. This is really only useful when you are also running aggregations, and want the aggs to be filtered differently from the search results.

Option 2) is the new syntax for the old filtered query (which is deprecated as well). This is part of the query, so it's execution is interleaved with the other queries, and it filters both the search and the aggregation results


(system) #3