# Insert object using java client 6.5

**URL:** <https://discuss.elastic.co/t/insert-object-using-java-client-6-5/229084>\
**Category:** Elasticsearch\
**Created:** [April 21, 2020, 3:44pm UTC](https://discuss.elastic.co/t/insert-object-using-java-client-6-5/229084 "2020-04-21T15:44:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamed](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Mohamed](https://discuss.elastic.co/u/Mohamed)\
**Post date:** [April 21, 2020, 3:44pm UTC](https://discuss.elastic.co/t/insert-object-using-java-client-6-5/229084/1 "2020-04-21T15:44:35Z")

</div>

Hello,

I want to insert an object using java high level rest client.

My mapping is the following:

```
 "images":{
           "type":"nested",
           "properties":{
			  "name":{
				  "type":"text"
			  },
              "url":{
                 "type":"text"
              }
           }
        }

```

and java code:  
\> [//productDb.getImages](https://productDb.getImages)() returns ArrayList of type Image: with attributes "name" and "url"

> ```
> productToIndex.put("images", new Gson().toJson(productDb.getImages()));
> IndexRequest indexRequest = new IndexRequest(ProductIndex.PRODUCT_INDEX, ProductIndex.TYPE)
> .source(productToIndex, XContentType.JSON);
> try {              
> restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);              
> } catch (Exception e) {
> logger.error("Data access error occured the entity persistence...", e);
> throw new Exception(e);
> }
> 
> ```

The error is:

`ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [images] tried to parse field [images] as object, but found a concrete value]]`

The concrete value:

> images -\> [{"name":"Capture.PNG","url":"/api/trader/files/2132132/Capture.PNG"},{"name":"payement.jpg","url":"/api/trader/files/31231321/payement.jpg"}]

==\> For me it seems OKay and I cannot understand why it returns an exception, if I replace productDb.getImages() with new Arraylist\<\>(); it works fine !

I cannot find an example of how to index arrays object using java, is there a solution to do it ?

Thanks.

---

<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:** [May 19, 2020, 3:44pm UTC](https://discuss.elastic.co/t/insert-object-using-java-client-6-5/229084/2 "2020-05-19T15:44:40Z")

</div>

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