【问题标题】:Elasticsearch nested field not exist query in DSL pythonDSL python中的Elasticsearch嵌套字段不存在查询
【发布时间】:2021-02-11 16:29:09
【问题描述】:

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

此弹性查询正在运行,但此查询的弹性 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"
            }
          }]
        }
      }
    }
  }
}

注意:我使用的是 elastic 6.7,elasticsearch-dsl 6.4.2

【问题讨论】:

    标签: elasticsearch elasticsearch-dsl elasticsearch-dsl-py


    【解决方案1】:

    终于找到了查询

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

    这可能对某人有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-10
      • 2018-10-17
      • 2020-09-04
      • 2021-05-20
      • 2021-07-08
      • 2021-11-15
      • 2021-11-10
      • 1970-01-01
      相关资源
      最近更新 更多