As far as search hits are concerned, they are the same thing, i.e. the hits you get will be correctly filtered according to either your filter in a filtered
query or the filter in your post_filter
.
However, as far as aggregations are concerned, the end result will not be the same. The difference between both boils down to what document set the aggregations will be computed on.
If your filter is in a filtered
query, then your aggregations will be computed on the document set selected by the query(ies) and the filter(s) in your filtered
query, i.e. the same set of documents that you will get in the response.
If your filter is in a post_filter
, then your aggregations will be computed on the document set selected by your various query(ies). Once aggregations have been computed on that document set, the latter is further filtered by the filter(s) in your post_filter
before returning the matching documents.
To sum it up,
- a
filtered
query affects both search results and aggregations - while a
post_filter
only affects the search results but NOT the aggregations