将对象插入嵌套数组

时间:2018-09-21 17:16:06

标签: java elasticsearch nested

我试图通过java api将对象插入嵌套数组,但是出现以下错误

MapperParsingException [[X]的对象映射尝试将字段[null]解析为对象,但找到了具体值]

通过Kibana进行操作,如下所示,相同的脚本有效。

关于如何解决此问题的任何想法?

以下是Java代码

HashMap<String, Object> params = new HashMap<>();
params.put("object", objectAsString);
Script script = new Script(ScriptType.INLINE, "painless", "ctx._source.media.add(params.object)", params);
UpdateResponse result = elasticClient.prepareUpdate(indexName, "Type", documentId).setScript(script).execute().actionGet();

通过基巴纳语

POST index/document/id/_update
{
   "script": {
      "lang": "painless",
      "inline": "ctx._source.media.add(params.object)",
      "params": {
         "object": {
           "description" : "A second image",
      "height" :  5,
      "weight": 5,
      "name" :  "Test",
      "orientation" :  "Vertical",
       "url" :  "htttp://newurl.jpg",
      "tags":["first","second"],
      "type":"image"
         }
      }
   }
}

模板映射如下:

"mappings": {
        "FOLDER_MODULE": {
            "properties": {
                "name": {
                    "type": "keyword"
                },
                "publisherId": {
                    "type": "keyword"
                },
                "username": {
                    "type": "keyword"
                },
                "media": {
                    "type": "nested",
                    "properties": {
                        "id": {
                            "type": "text"
                        },
                        "name": {
                            "type": "text"
                        },
                        "publisherId": {
                            "type": "short"
                        },
                        "tags": {
                            "type": "text"
                        },
                        "description": {
                            "type": "text"
                        },
                        "url": {
                            "type": "keyword"
                        },
                        "createdDate": {
                            "format": "strict_date_optional_time||epoch_millis",
                            "type": "date"
                        },
                        "height": {
                            "type": "float"
                        },
                        "width": {
                            "type": "float"
                        },
                        "weight": {
                            "type": "float"
                        },
                        "orientation": {
                            "type": "keyword"
                        },
                        "status": {
                            "type": "keyword"
                        },
                        "type": {
                            "type": "keyword"
                        },
                        "username": {
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    }

0 个答案:

没有答案