如何查询所有嵌套字段为空的数据?弹性搜索 v.7

发布于 2025-01-13 12:31:06 字数 1240 浏览 6 评论 0原文

我正在尝试从索引中获取城市为空的所有记录。

源看起来像:

  "_index": "potatos_index",
            "_type": "_doc",
            "_id": "1240862",
            "_score": 14.41736,
            "_source": {
                "accountNumber": "1121212",
                "accountType": "Customer",
                "currency": "USD",
                "country": "USA",
                "cities": null,
           }

      "_index": "potatos_index",
                "_type": "_doc",
                "_id": "1240862",
                "_score": 14.41736,
                "_source": {
                    "accountNumber": "1121212",
                    "accountType": "Customer",
                    "currency": "USD",
                    "country": "USA",
                    "cities": [
                        {
                            "id": "1111",
                            "globalId": "1111"
                        }],
               }

因此,当我尝试仅搜索那些具有 cities: null 的源时,我收到不同类型的错误。

必须不+存在返回包含非空城市的源。

我尝试过不同类型的脚本来过滤数据,但没有结果。

_mapping 请求,城市具有嵌套类型。

"cities": {
                    "type": "nested",
                    "properties": {

请指教

I'm trying to get all records from index that has cities as null.

Source looks like:

  "_index": "potatos_index",
            "_type": "_doc",
            "_id": "1240862",
            "_score": 14.41736,
            "_source": {
                "accountNumber": "1121212",
                "accountType": "Customer",
                "currency": "USD",
                "country": "USA",
                "cities": null,
           }

      "_index": "potatos_index",
                "_type": "_doc",
                "_id": "1240862",
                "_score": 14.41736,
                "_source": {
                    "accountNumber": "1121212",
                    "accountType": "Customer",
                    "currency": "USD",
                    "country": "USA",
                    "cities": [
                        {
                            "id": "1111",
                            "globalId": "1111"
                        }],
               }

So when I try to search only those source that has cities: null I receive different kinds of errors.

must_not + exists returns sources that contains non-null cities.

I have tried different kind of script to filter out the data but no result.

_mapping request, cities has type nested.

"cities": {
                    "type": "nested",
                    "properties": {

Please advice

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2025-01-20 12:31:06

您是否以嵌套方式编写了 exists 查询?

{
    "query": {
     "bool" : {
      "must_not": [
      "nested": {
        "path": "cities",
        "query": {
                "exists": {
                  "field": "cities"
                }
        }
      } ]
    }
   }
}

基于此 <代码>讨论

Did you write the exists query in nested manner?

{
    "query": {
     "bool" : {
      "must_not": [
      "nested": {
        "path": "cities",
        "query": {
                "exists": {
                  "field": "cities"
                }
        }
      } ]
    }
   }
}

Based on this discussion

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文