代码之家  ›  专栏  ›  技术社区  ›  villasv

在deep Elasticsearch文档中递归初始化带有空对象的字段

  •  2
  • villasv  · 技术社区  · 5 年前

    {
      "doc": {
        "properties": {
          "biography": {
            "properties": {
              "en": {
                "properties": {
                  "event": {
                    "type": "nested",
                    "properties": {
                      "id": {
                        "type": "long"
                      },
    ...
    

    当我以后想添加一个新的 event

    if (ctx._source.biography == null)
      ctx._source.biography = new HashMap();
    if (ctx._source.biography.${language} == null)
      ctx._source.biography.${language} = new HashMap();
    if (ctx._source.biography.${language}.event == null) {
      ctx._source.biography.${language}.event = [ params.event ]
    } else {
      ctx._source.biography.${language}.event += [ params.event ]
    }
    

    有没有办法简化这些初始化步骤?

    0 回复  |  直到 5 年前
    推荐文章