elasticsearch - elasticsearch中must_not和filter的区别

标签 elasticsearch

谁能给我解释一下elasticsearch中must_not和filter的区别?

例如这里(取自 elasticsearch definitive guide ),为什么 must_not 不也用于范围?

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

具体看this documentation , 在我看来它们是完全一样的:

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: 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.

最佳答案

filter用于匹配的文档需要显示在结果中,而must_not用于匹配的文档不显示在结果中。进一步分析:

过滤器:

  1. 写在Filter context .
  2. 不影响成绩得分。
  3. 匹配的查询结果将出现在结果中。
  4. 基于精确匹配,而非部分匹配。

不得:

  1. 它在同一个过滤器上下文中再次写入。
  2. 表示不会影响结果的得分。
  3. 符合此条件的文档不会出现在结果中。
  4. 基于精确匹配。

Tabular comparision

关于elasticsearch - elasticsearch中must_not和filter的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47226479/

相关文章:

java - 带参数的 Elasticsearch java HighLevel 客户端更新脚本

elasticsearch - Kubernetes Persistent Volume在GCE上不起作用

elasticsearch - 无法将Marvel安装到Kibana中

mongodb - DynamoDB vs ElasticSearch vs S3 - 哪种服务用于超快获取/放置 10-20MB 文件?

elasticsearch - 为什么新创建的索引在“发现”或“创建索引”模式中不可用?

elasticsearch - ElasticSearch 可以在本地用Electron 打包吗?

elasticsearch - 范围 ElasticSearch 聚合

ruby-on-rails - 我收到错误 'Unknown key for a VALUE_STRING in [q]'

linux - Zipkin + Elasticsearch (ELK) 不创建索引

elasticsearch - elasticsearch是否可以结合score_mode用于function_score查询