# Example of mapping a list of complex objects via Java API

**URL:** <https://discuss.elastic.co/t/example-of-mapping-a-list-of-complex-objects-via-java-api/6671>\
**Category:** Elasticsearch\
**Created:** [February 10, 2012, 3:33pm UTC](https://discuss.elastic.co/t/example-of-mapping-a-list-of-complex-objects-via-java-api/6671 "2012-02-10T15:33:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [February 10, 2012, 3:33pm UTC](https://discuss.elastic.co/t/example-of-mapping-a-list-of-complex-objects-via-java-api/6671/1 "2012-02-10T15:33:43Z")

</div>

I've been trying to figure out how to add a list of complex objects via the  
Java API as illustrated in the guide here:

[http://www.elasticsearch.org/guide/reference/mapping/array-type.html](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)

1. Is there an example of how to do this?
2. I'd also be interested an example of how to populate the index via  
Java API.

I'm using version 0.18.7.

Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 12, 2012, 2:07pm UTC](https://discuss.elastic.co/t/example-of-mapping-a-list-of-complex-objects-via-java-api/6671/2 "2012-02-12T14:07:20Z")

</div>

The index API ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/index_.html)) can accept any form of json data (byte array, a string). So, you can create your own json with your favorite json lib, and feed it to the index operation (using the several setSource methods).

There is a built in embedded API to generate json (or smile format, which is a binary json format created by the jackson lib). Thats the one used in the example in the link above. It as different startArray methods.

On Friday, February 10, 2012 at 5:33 PM, Shane Witbeck wrote:

> I've been trying to figure out how to add a list of complex objects via the Java API as illustrated in the guide here:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/array-type.html)
> 
> Is there an example of how to do this?  
> I'd also be interested an example of how to populate the index via Java API.  
> I'm using version 0.18.7.
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [February 12, 2012, 6:26pm UTC](https://discuss.elastic.co/t/example-of-mapping-a-list-of-complex-objects-via-java-api/6671/3 "2012-02-12T18:26:29Z")

</div>

You didn't really answer my questions. I was looking for a specific example  
using the Java API.

I resorted to externalizing the mapping to a file similar to how it's done  
in ES tests.

Thanks anyway.

---

<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:** [July 6, 2017, 3:39am UTC](https://discuss.elastic.co/t/example-of-mapping-a-list-of-complex-objects-via-java-api/6671/4 "2017-07-06T03:39:41Z")

</div>


