首页 > 解决方案 > 嵌套对象数组的 Elasticsearch 查询

问题描述

我正在努力解决 ElasticSearch 上的查询问题。我记录了这种对象:

{
    "obj_id": 1,
    "label": "label obj 1",
    "array_of_nested": [{
            "nested_id": 1,
            "label": "label nested obj1"
        }, {
            "nested_id": 2,
            "label": "label nested obj2"
        }
    ]
}, {
    "obj_id": 2,
    "label": "label obj 2",
    "array_of_nested": [{
            "nested_id": 3,
            "label": "label nested obj1"
        }, {
            "nested_id": 4,
            "label": "label nested obj2"
        }
    ]
}

我正在尝试编写一个查询以在 array_of_nested 属性中查找所有nested_id 为 2 的对象,但到目前为止无法使其工作。:/

谢谢 !

标签: elasticsearchelasticsearch-queryelasticsearch-nested

解决方案


你能试试这个吗?

{
  "query": {
    "match": {
      "array_of_nested.nested_id": 2
    }
  }
}

推荐阅读