过滤器是在过滤查询的内部还是外部有关系吗? [英] Does it matter if the filter is inside or outside a filtered query?

查看:22
本文介绍了过滤器是在过滤查询的内部还是外部有关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这两个给我相同的结果,但在内部或外部使用过滤器有什么区别?在性能或幕后操作方面有区别吗?

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" }
}

推荐答案

在查询中过滤

Elasticsearch 将以更有效的方式执行查询和过滤,以减少结果集并尽快为您提供答案.这称为 过滤查询

首先运行查询,然后然后过滤结果,然后将它们返回给客户端.这被称为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆