Elasticsearch嵌套搜索-不得包含

问题描述 投票:0回答:1

我正在包含嵌套列表的文档

fixed_fields: [
    {
       id: 12,
       value: "someValue"
    },
    {
       id: 38,
       value: "someValue2"
    },
]

现在我需要用id = 38查找所有没有固定字段的文档>

我尝试过:

            "bool":{
              "must":[
                {
                  "nested":{
                    "path":"fixed_fields",
                    "filter":{
                      "bool":{
                        "must_not":[
                          {
                            "term":{
                              "fixed_fields.id":38
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              ]
            }

但是我得到了所有具有任何fixed_fields的文档作为响应,包括ID为38的文档。

我在2.4.6版中使用的是Elastic,但没有选择升级的选项

我正在包含包含嵌套列表fixed_fields的文档:[{id:12,value:“ someValue”},{id:38,value:“ someValue2”},]现在,我需要查找所有...

elasticsearch
1个回答
2
投票

尝试以下方法:

{
 "bool": {
    "must_not": [{
        "nested": {
            "path": "fixed_fields",
            "filter": {
                "term": {
                    "fixed_fields.id": 38
                }
            }
        }
    }]
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.