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
filteredquery affects both search results and aggregations - while a
post_filteronly affects the search results but NOT the aggregations
本文探讨了在Elasticsearch中使用filtered query与post_filter的区别,特别是在搜索结果和聚合计算方面。filtered query同时影响搜索结果和聚合,而post_filter仅影响搜索结果,不影响聚合计算。
1126

被折叠的 条评论
为什么被折叠?



