# Insert object to nested array

**URL:** https://discuss.elastic.co/t/insert-object-to-nested-array/149491
**Category:** Elasticsearch
**Created:** [September 21, 2018, 4:47pm UTC](https://discuss.elastic.co/t/insert-object-to-nested-array/149491 "2018-09-21T16:47:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Martin\_Blaustein](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@Martin\_Blaustein](https://discuss.elastic.co/u/Martin_Blaustein)
#### Post date: [September 21, 2018, 4:47pm UTC](https://discuss.elastic.co/t/insert-object-to-nested-array/149491/1 "2018-09-21T16:47:34Z")

</div>

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

```auto
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

```auto
{
   "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"
         }
      }
   }
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 19, 2018, 4:47pm UTC](https://discuss.elastic.co/t/insert-object-to-nested-array/149491/2 "2018-10-19T16:47:37Z")

</div>

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