# Multivalued fields via Java API

**URL:** <https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331>\
**Category:** Elasticsearch\
**Created:** [January 9, 2012, 8:44pm UTC](https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331 "2012-01-09T20:44:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)\
**Post date:** [January 9, 2012, 8:44pm UTC](https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331/1 "2012-01-09T20:44:02Z")

</div>

Hi,

I have an integer field in my index which I would like to be  
multivalued.

I am using the Java API, and I prefer to use  
the .setSource(Map\<String,Object\>) method of setting the source.

In the case of a multivalued field, what object should I pass? Will a  
List or Set of Integers work, or is it expecting an Array?

What kind of a collection should I expect when reading back one of  
these documents? Is it correct to assume that instances with one value  
will be returned as an Integer while instances with multiple values  
will be returned as some kind of a collection or array?

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:** [January 9, 2012, 9:08pm UTC](https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331/2 "2012-01-09T21:08:18Z")

</div>

Yes, a List of values will do.

On Mon, Jan 9, 2012 at 10:44 PM, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) wrote:

> Hi,
> 
> I have an integer field in my index which I would like to be  
> multivalued.
> 
> I am using the Java API, and I prefer to use  
> the .setSource(Map\<String,Object\>) method of setting the source.
> 
> In the case of a multivalued field, what object should I pass? Will a  
> List or Set of Integers work, or is it expecting an Array?
> 
> What kind of a collection should I expect when reading back one of  
> these documents? Is it correct to assume that instances with one value  
> will be returned as an Integer while instances with multiple values  
> will be returned as some kind of a collection or array?
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 10, 2012, 12:01am UTC](https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331/3 "2012-01-10T00:01:29Z")

</div>

It is interesting to see that there is now support for Iterable. In  
the past, you told me the limitation was because of JSON, which I did  
not understand at the time. Then I understood that the idea was to  
have the REST API identical to the Java API in terms of types  
supported.

On Mon, Jan 9, 2012 at 1:08 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Yes, a List of values will do.
> 
> On Mon, Jan 9, 2012 at 10:44 PM, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) wrote:
> 
> > Hi,
> > 
> > I have an integer field in my index which I would like to be  
> > multivalued.
> > 
> > I am using the Java API, and I prefer to use  
> > the .setSource(Map\<String,Object\>) method of setting the source.
> > 
> > In the case of a multivalued field, what object should I pass? Will a  
> > List or Set of Integers work, or is it expecting an Array?
> > 
> > What kind of a collection should I expect when reading back one of  
> > these documents? Is it correct to assume that instances with one value  
> > will be returned as an Integer while instances with multiple values  
> > will be returned as some kind of a collection or array?
> > 
> > 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:** [January 10, 2012, 8:56am UTC](https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331/4 "2012-01-10T08:56:43Z")

</div>

I told you to open an issue... 🙂

On Tue, Jan 10, 2012 at 2:01 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> It is interesting to see that there is now support for Iterable. In  
> the past, you told me the limitation was because of JSON, which I did  
> not understand at the time. Then I understood that the idea was to  
> have the REST API identical to the Java API in terms of types  
> supported.
> 
> On Mon, Jan 9, 2012 at 1:08 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Yes, a List of values will do.
> > 
> > On Mon, Jan 9, 2012 at 10:44 PM, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com)  
> > wrote:
> > 
> > > Hi,
> > > 
> > > I have an integer field in my index which I would like to be  
> > > multivalued.
> > > 
> > > I am using the Java API, and I prefer to use  
> > > the .setSource(Map\<String,Object\>) method of setting the source.
> > > 
> > > In the case of a multivalued field, what object should I pass? Will a  
> > > List or Set of Integers work, or is it expecting an Array?
> > > 
> > > What kind of a collection should I expect when reading back one of  
> > > these documents? Is it correct to assume that instances with one value  
> > > will be returned as an Integer while instances with multiple values  
> > > will be returned as some kind of a collection or array?
> > > 
> > > 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:** [July 6, 2017, 3:43am UTC](https://discuss.elastic.co/t/multivalued-fields-via-java-api/6331/5 "2017-07-06T03:43:16Z")

</div>


