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

问题描述

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

Can someone explain to me what the difference between must_not and filter is in 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:

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之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:31