具有嵌套和非嵌套子句的Elasticsearch bool查询

时间:2018-02-08 19:04:39

标签: elasticsearch search nested boolean

我有嵌套和非嵌套组件的数据。我无法重新映射数据,它正在生产中。样品是

height

我需要在嵌套值和非嵌套值中进行查询。即,所有未结婚的参赛作品#39;但是他的名字是汤姆'。

为了查询汤姆',我会做

{
   "name":[
      "first":"Tom",
      "last":"Smith"
   ],
   "status":"married"
}

但是如何将其与状态(非嵌套)的must_not查询结合起来

1 个答案:

答案 0 :(得分:1)

您需要在must_not后面添加must。我在我的环境中对此进行了测试(除了我使用term而不是match)并且它过滤了不需要的元素。

GET /_search
{
  "query": {
    "nested": {
      "path": "name",
      "query": {
        "bool": {
          "must": [
            { 
              "match" : {"name.first" : "Tom"}}
          ],
          "must_not": [
            { 
              "match" : {"status" : "married"}}
          ]
        }
      }
    }
  }
}
相关问题