Elasticsearch嵌套字段在DSL python中不存在查询

问题描述

我在文档中有一个嵌套数据映射,我想查询嵌套字段是否不存在。

此弹性查询正在工作,但此查询上的弹性DSL表示将是什么?

获取产品/ _搜索

{
  "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:我使用的是Elastic 6.7,elasticsearch-dsl 6.4.2

解决方法

最后,我找到了查询

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

这可能对某人有帮助

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...