在dsl python中查询elasticsearch嵌套字段不存在

ltskdhd1  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(505)

我在文档中有一个嵌套数据Map,我想查询嵌套字段是否不存在。
这个弹性查询正在工作,但是这个查询上的弹性dsl表示是什么?
获取产品/\u搜索

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "attributes",
            "query": {
              "exists": {
                "field": "attributes.value"
              }
            }
          }
        }
      ]
    }
  }
}

我试过这个,但没用

ProductDocument.search().query(
    "nested",
    path="attributes",
    query=(~Q('exists', field='attributes.value'))
)

这个dsl查询表示为,我认为是错误的

{
  "query": {
    "nested": {
      "path": "attributes",
      "query": {
        "bool": {
          "must_not": [{
            "exists": {
              "field": "attributes.value"
            }
          }]
        }
      }
    }
  }
}

n、 b:我用的是Elastic6.7,ElasticSearchDSL6.4.2

yuvru6vn

yuvru6vn1#

最后,我找到了查询

ProductDocument.search().query(~Q(
    "nested",
    path="attributes",
    query=Q("exists", field='attributes.value'))
))

可能对某人有帮助

相关问题