简体   繁体   English

elasticsearch 如何在同一查询中决定必须和过滤条件?

[英]How elasticsearch decides must and filter terms in same query?

The following query includes must and filter contexts in same query.以下查询包括同一查询中的必须和过滤上下文。

GET /_search
{
  "query": { 
    "bool": { 
      "must": [
        { "match": { "title":   "Search"        }},
        { "match": { "content": "Elasticsearch" }}
      ],
      "filter": [ 
        { "term":  { "status": "published" }}
      ]
    }
  }
}

if there are some documents that matches with must logic but not matches with filer logic, so I am getting no result?如果有一些文档与必须逻辑匹配但与文件管理器逻辑不匹配,那么我没有得到任何结果? Is filter most important?过滤器最重要吗? How works this query order?这个查询顺序是如何工作的? First must logic and then filter logic?首先必须逻辑,然后过滤逻辑?

Here it will match all the conditions of MUST & FILTERS.在这里它将匹配 MUST & FILTERS 的所有条件。 You can see MUST & FILTER something like AND query.您可以看到 MUST & FILTER 之类的 AND 查询。 So the query will go like title="search" AND content="Elasticsearch" AND status="published" .所以查询将 go 像title="search" AND content="Elasticsearch" AND status="published"

The only difference is MUST contributes to scoring where FILTER is not.唯一的区别是必须有助于在 FILTER 没有的情况下进行评分。

So if you hit same query like below,因此,如果您点击如下相同的查询,

GET /_search
{
  "query": { 
    "bool": { 
      "must": [
        { "match": { "title":   "Search"        }},
        { "match": { "content": "Elasticsearch" }},
        { "term":  { "status": "published" }}
      ]
    }
  }
}

You will see the different _score value with same result.您将看到具有相同结果的不同_score值。

So simple is if you want to ignore scoring just use filter.很简单,如果您想忽略评分,只需使用过滤器。

Mostly filters are use with conditions like < , > , <= , >= , = or where you don't want score.大多数情况下,过滤器用于<><=>==等条件或您不想要得分的地方。

Note : Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.注意:经常使用的过滤器将被 Elasticsearch 自动缓存,以加快性能。

Check more in doc文档中查看更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 过滤 Elasticsearch 术语查询 - Filter on Elasticsearch terms query 如何在Elasticsearch中与filter和must_not一起编写至少N个词查询? - How to write an at-least-N-terms query together with filter and must_not in Elasticsearch? 如何使用Elasticsearch 1.4.5中必须使用范围和术语进行过滤的方法 - How to use must filter with range and terms in elasticsearch 1.4.5 Elasticsearch:突出显示查询词,而不是过滤词? - Elasticsearch: highlight on query terms, not filter terms? 对于 Elasticsearch,如何在 filter-&gt;terms 查询中使用 OR 而不是 AND? - With Elasticsearch, how to use an OR instead of AND within filter->terms query? Elasticsearch如何替换“术语”查询? - Elasticsearch how to replace “terms” query? Elasticsearch查询同时使用&#39;terms&#39;和&#39;missing&#39; - Elasticsearch query that use 'terms' and 'missing' at same time Elasticsearch 查询多字段术语和多字段不能匹配查询 - Elasticsearch query for multiple fields terms and multile filelds must not match query Elasticsearch 嵌套查询,必须和不能具有相同字段 - Elasticsearch Nested Query with Must and Must Not with same fields 如何在ElasticSearch中过滤热门词汇聚合? - How to filter top terms aggregation in ElasticSearch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM