1、概念
bool (布尔)过滤器。 这是个 复合过滤器(compound filter) ,它可以接受多个其他过滤器作为参数,并将这些过滤器结合成各式各样的布尔(逻辑)组合。
格式
一个 bool 过滤器由三部分组成:
{
"bool" : {
"must" : [],
"should" : [],
"must_not" : [],
}
}
must
所有的语句都 必须(must) 匹配,与 AND 等价。
must_not
所有的语句都 不能(must not) 匹配,与 NOT 等价。
should
至少有一个语句要匹配,与 OR 等价。
2、实战
查询title:是chrome或者firefox的数据:should默认是至少有一条匹配 如下例:
{
"bool": {
"should": [
{ "term": { "title": "chrome" }},
{ "term": { "title": "firefox" }}
]
}
}
查询title:是chrome或者firefox或者safari的数据:因为只有三条语句,term 查询的参数 minimum_should_match
值 75% 会被截断成 2
。即三条 should
语句中至少有两条必须匹配 如下例:
{
"bool": {
"should": [
{ "term": { "title": "chrome" }},
{ "term": { "title": "firefox" }},
{ "term": { "title": "safari" }}
],
"minimum_should_match": 2
}
}
查询title:是必须既有chrome 又有 firefox,强查询 如下例:
{
"bool": {
"must": [
{ "term": { "title": "chrome" }},
{ "term": { "title": "firefox" }}
]
}
}
查询title:是必须不含有chrome 强查询 如下例:
{
"bool": {
"must_not": [
{ "term": { "title": "chrome"}}
]
}
}
部分参考来自:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/160916.html