ElasticSearch系列--API

布尔查询

其他网址

ElasticSearch查询 第五篇:布尔查询 - 悦光阴 - 博客园
Bool Query | Elasticsearch Reference [6.8] | Elastic

《从Lucene到Elasticsearch:全文检索实战》=> 6.4.2 bool query

简介

  • must子句:文档必须匹配must查询条件;(相当于逻辑与)
  • should子句:文档应该匹配should子句查询的一个或多个;(相当于逻辑或)
  • must_not子句:文档不能匹配该查询条件;(相当于逻辑与)
  • filter子句:过滤器,文档必须匹配该过滤条件,跟must子句的唯一区别是,filter不影响查询的score;(相当于逻辑与)

注意

四个子句,都可以是数组字段,因此,支持嵌套逻辑操作的查询。而且,写为数组格式时,Kibana有语法提示。

详解

should

通常should子句是数组字段,包含多个should子查询,默认情况下,匹配的文档必须满足其中大于等于0个子查询条件。该数值由minimum_should_match控制。

如果查询语句中有must或者filter,文档就算是没有匹配should中的项也会被查到,在这种情况下,这些子句仅用来影响评分。(也就是minimum_should_match为0)
如果查询语句中没有must也没有filter,那么文档必须匹配should中的至少一项。(也就是minimum_should_match为1)

原文如下:

扫描二维码关注公众号,回复: 12432408 查看本文章

The clause (query) should appear in the matching document. If the bool query is in a query context and has a must or filter clause then a document will match the bool query even if none of the should queries match. In this case these clauses are only used to influence the score. If the bool query is in a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by setting the minimum_should_match parameter.

猜你喜欢

转载自blog.csdn.net/feiying0canglang/article/details/112061243