使用 man ascii 来查看 ASCII 表。

请问Elasticsearch 将or放在and里面如何实现

Elasticsearch | 作者 chaochao6411 | 发布于2019年03月21日 | 阅读数:3794

比如 A and B and ((C and D) or E)
已邀请:

Jea - 一只猿

赞同来自:

差不多就这样, 循环嵌套bool,去吧; 有需求的话加上minimum_should_match控制should
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"a": "a",
"b:"b
}
}
]
}
},
{
"bool": {
"should":
{
"term": {
"c": c,"d":d
}
}
]
}
}
]
}
 
 
下面的json是我单元测试写循环嵌套 or and 条件用的, 你参考下
 
 
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"house_id": "594243b87f8b9a3a08d2b1a5"
}
}
]
}
},
{
"bool": {
"must_not": [
{
"term": {
"system": true
}
}
]
}
},
{
"bool": {
"must_not": [
{
"term": {
"types": 1015
}
}
]
}
}
],
"should": [
{
"bool": {
"should": {
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"term": {
"id": 1
}
}
]
}
},
{
"bool": {
"must_not": [
{
"term": {
"types": 1009
}
},
{
"term": {
"types": 1010
}
},
{
"term": {
"types": 1016
}
},
{
"term": {
"types": 1017
}
},
{
"term": {
"types": 1012
}
}
]
}
}
]
}
}
}
},
{
"bool": {
"should": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"admin_id": "55f238add6e4688e648b45d8"
}
}
]
}
},
{
"bool": {
"must": [
{
"terms": {
"types": [
1009,
1010,
1016,
1017,
1012
]
}
}
]
}
}
]
}
}
}
}
]
}
}
}
}
}

bellengao - 博客: https://www.jianshu.com/u/e0088e3e2127

赞同来自:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "a": "1"
          }
        },
        {
          "term": {
            "b": "2"
          }
        },
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "c": "3"
                      }
                    },
                    {
                      "term": {
                        "d": "4"
                      }
                    }
                  ]
                }
              },
              {
                "term": {
                  "e": "5"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

实战方法论:《DSL的诞生 | 复杂sql转成Elasticsearch DSL深入详解》, 一起来围观吧 https://blog.csdn.net/wojiushi ... 56221

要回复问题请先登录注册