首页 > 解决方案 > 在 ElasticSearch 中映射未知数量的嵌套对象

问题描述

给定以下嵌套对象

{
  "nestedParent":{
    "type":"nested",
    "dynamic":"true",
    "properties":{
      ...
    }
  }
}

我也需要它的所有属性都属于该nested类型。如何为未知数量的嵌套子级生成映射?

功能上等于:

{
  "nestedParent":{
    "type":"nested",
    "dynamic":"true",
    "properties":{

      "nestedChild1":{
        "type":"nested",
        "dynamic":"true",
        "properties":{
          ...
        }
      },
      "nestedChild2":{
        "type":"nested",
        "dynamic":"true",
        "properties":{
          ...
        }
      },
      "nestedChild3":{
        "type":"nested",
        "dynamic":"true",
        "properties":{
          ...
        }
      },

      ...
    }
  }
}

我确实知道嵌套子项的结构,但我不知道他们的键/名称。

标签: elasticsearchelasticsearch-mapping

解决方案


您将需要一些通用数据结构,例如 Map of Maps 来映射未知结构。在 Java 中,有很多针对这个问题的实现。例如,请看这篇文章,它描述了如何使用杰克逊映射器处理(反)序列化未知 json:https ://www.baeldung.com/jackson-json-node-tree-model


推荐阅读