Insert object to nested array

I'm trying to insert an object to a nested array through the java api, but I get the following error

MapperParsingException[object mapping for [X] tried to parse field [null] as object, but found a concrete value]

doing it through Kibana as shown below the same script works.

Any ideas on how to fix this?

The java code is the following

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();

Trhough Kibana

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"
         }
      }
   }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.