与或非
must :: 多个查询条件的完全匹配 类似于 and
must_not :: 多个查询条件的相反匹配 类似于 not
should :: 至少有一个查询条件匹配 类似于 or
filter::过滤
与或非嵌套写法
{
"query": {
"bool": {
"must": [
{
"match": {
"标题": "南通"
}
},
{
"bool": {
"should": [
{
"match": {
"地址": "海门"
}
},
{
"match": {
"地址": "崇川"
}
}
],
"minimum_should_match": 1
}
},
{
"bool": {
"should": {
"nested": {
"path": "归属地",
"query": {
"bool": {
"should": [
{
"match": {
"归属地.地市": "南通"
}
},
{
"match": {
"归属地.地市": "无锡"
}
}
],
"minimum_should_match": 1
}
}
}
}
}
}
],
"must_not": {
"match": {
"状态": "无效"
}
}
}
}
}
这篇博客详细介绍了布尔查询在搜索过滤中的应用,包括must(与)、must_not(非)和should(或)条件的使用。通过示例展示了如何在地址字段中匹配海门或崇川,并在归属地中匹配南通或无锡,同时排除状态为'无效'的记录。布尔查询的嵌套结构使得复杂过滤条件的设定更为灵活。

2356

被折叠的 条评论
为什么被折叠?



