如果筛选器在筛选查询内部或外部,是否重要? [英] Does it matter if the filter is inside or outside a filtered query?
问题描述
虽然这两者给了我相同的结果,但内部或外部的过滤器有什么区别?在表现或幕后行为方面有差异吗?
While these two are giving me the same result, what is the difference between having the filter inside or outside? Is there a difference in terms of performance or the actions behind the scenes?
"query": {
"filtered": {
"query": { "match": { "email": "business opportunity" }},
"filter": { "term": { "folder": "inbox" }}
}
}
"query": {
"filtered": {
"query": { "match": { "email": "business opportunity" }}
}
},
"filter": {
"term": { "folder": "inbox" }
}
推荐答案
在查询
内过滤弹性搜索将执行查询并过滤出更多的方式有效地减少结果集,并尽可能快地得到答案。
这被称为 filtered_query
查询首先运行, strong> then 结果将被过滤,然后返回到客户端。
这被称为 post_filter 。
The query is run first and then results are filtered before returning them to the client. This is referred to as a post_filter.
虽然post_filter效率较低,但与聚合组合时可能会很有用 - 聚合值不会占用帐户post_filter,即聚合只会在查询结果上。
Although a post_filter is less efficient, it can be useful when combining with an aggregation - the aggregated values won't take into account the post_filter, i.e. the aggregation will only be on the query results.
这篇关于如果筛选器在筛选查询内部或外部,是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!