了解布尔过滤器 [英] Understanding of bool filter

查看:468
本文介绍了了解布尔过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据弹性搜索文档,请参阅 http:// www .elastic.co / guide / en / elasticsearch / guide / master / combine-filters.html ,一个布尔过滤器可以如下:

According to elasticsearch doc at http://www.elastic.co/guide/en/elasticsearch/guide/master/combining-filters.html, a bool filter can be the following:

{
   "bool" : {
      "must" :     [
          A,
          B
       ],
      "should" :   [
          C,
          D
       ],
      "must_not" : [
          E,
          F
       ],
   }
}

在意义上,它等同于以下逻辑操作:

In meaning, it is equivalent to the following logic operations:

A and B and (C or D) and (not E) and (not F)

这是否正确?

谢谢!

推荐答案

正如Andrei在评论中指出的那样,对于 bool 过滤器

As Andrei pointed out in the comments, this is the correct understanding for a bool filter:


  • 必须可以翻译为(A和B)

  • 应该可以翻译成(C或D)

  • must_not 可以翻译为((不是E)和(不是F))

  • must can be translated as (A and B)
  • should can be translated as (C or D)
  • must_not can be translated as ((not E) and (not F))

它们中的每一个都是一个独立的操作,但它们可以与您所显示的完全相同。

Each one of them is an operation that stands alone, but they can be combined exactly as you have shown.

(A and B) and (C or D) and ((not E) and (not F))

以布尔逻辑表示,与(not(E和F))不一样的原因是因为相同说:((不是E)或(不是F))。如果 E 与说 field == 5 F 与说 field == 6 相同,那么与 field!= 5或field!= 6 ,这将永远是真的!

Speaking in terms of boolean logic, the reason that it's not the same thing as (not (E and F)) is because that is the same as saying ((not E) or (not F)). If E is the same as saying field == 5 and F is the same as saying field == 6, then that is the same as field != 5 or field != 6, which is always going to be true!

这导致了一种不同的方式:

This leads to looking at it a different way:


  • must_not 可以翻译成(不是(E或F)) li>
  • must_not can be translated as (not (E or F))

换句话说,如果任何过滤器不匹配,文档不匹配。这将导致组合版本略微简化:

In other words, the document does not match if any filter does not match. This leads to a slightly simplified version of the combined version:

(A and B) and (C or D) and (not (E or F))

这篇关于了解布尔过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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