Insert object using java client 6.5

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

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