elasticsearch中must_not和filter之间的区别 [英] Difference between must_not and filter in elasticsearch

查看:2565
本文介绍了elasticsearch中must_not和filter之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释must_not和filter之间有什么区别吗?

Can someone explain to me what the difference between must_not and filter is in elasticsearch?

例如此处(摘录于 elasticsearch最终指南),为什么不必须也不要在该范围内使用?

E.g. here (taken from elasticsearch definitive guide), why isn't must_not also used for the range?

{
    "bool": {
        "must":     { "match": { "title": "how to make millions" }},
        "must_not": { "match": { "tag":   "spam" }},
        "should": [
            { "match": { "tag": "starred" }}
        ],
        "filter": {
          "range": { "date": { "gte": "2014-01-01" }} 
        }
    }
}

专门查看此文档,在我看来,它们是完全相同:

Specifically looking at this documentation, it appears to me that they are exactly the same:


过滤器:子句(查询)必须出现在匹配的文档中。但是,与查询分数不同的是,忽略该分数。过滤子句在过滤器上下文中执行,这意味着计分被忽略,并且子句被视为用于缓存。

filter: The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.

must_not :子句(查询)不得出现在匹配文件。子句在过滤器上下文中执行,这意味着计分被忽略,并且子句被视为用于缓存。因为忽略了评分,所以所有文档的评分都为0。

must_not: The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned.


推荐答案

基本上, 过滤器 = 必须,但不计分。

Basically, filter = must but without scoring.

必须不要表示必须满足的条件,而过滤器(和 )表示为了选择文档而必须满足的条件。

must_not expresses a condition that MUST NOT be met, while filter (and must) express conditions that MUST be met in order for a document to be selected.

这篇关于elasticsearch中must_not和filter之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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