# Java API ES 0.90.9 Array (2 elements) in search result gets only one value in SearchHitField.getValues()

**URL:** <https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495>\
**Category:** Elasticsearch\
**Created:** [January 30, 2014, 10:27am UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495 "2014-01-30T10:27:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Pape](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@Martin\_Pape](https://discuss.elastic.co/u/Martin_Pape)\
**Post date:** [January 30, 2014, 10:27am UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/1 "2014-01-30T10:27:14Z")

</div>

Hi,

the json (logged with SearchResponse.toString()) of my search result looks  
like this:  
...  
"title": "abc, cdf Systemfunktionen",  
\* "type": [\*

- 

```
             "abc",*

```

- 

```
             "cdf"*

```

- 

```
          ]*
         ...

```

so field: type is an array of 2 values.  
Then in  
SearchHitField.getValues().size()  
I get only 1.  
How to get both values "abc" and "cdf" from the SearchHitField so  
SearchHitField.getValues().size() == 2  
?

Please advice and many thanks in advance!

Martin

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2014, 5:01pm UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/2 "2014-01-30T17:01:38Z")

</div>

I guess you did not ask for specific fields in your query so only \_source is returned by default.

You can get the full Json document back. Have a look at [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L392](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L392)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 30 janvier 2014 at 11:27:18, Martin Pape ([pape.martin@gmail.com](mailto:pape.martin@gmail.com)) a écrit:

Hi,

the json (logged with SearchResponse.toString()) of my search result looks like this:  
...  
"title": "abc, cdf Systemfunktionen",  
"type": [  
"abc",  
"cdf"  
]  
...  
so field: type is an array of 2 values.  
Then in  
SearchHitField.getValues().size()  
I get only 1.  
How to get both values "abc" and "cdf" from the SearchHitField so  
SearchHitField.getValues().size() == 2  
?

Please advice and many thanks in advance!

Martin

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.52ea8572.721da317.45fa%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ea8572.721da317.45fa%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Martin\_Pape](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@Martin\_Pape](https://discuss.elastic.co/u/Martin_Pape)\
**Post date:** [January 30, 2014, 5:08pm UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/3 "2014-01-30T17:08:45Z")

</div>

Hi and thanks for the reply.

> I guess you did not ask for specific fields in your query so only \_source  
> is returned by default.  
> No, I was specifying the fields to return. "type" was one of them.

> You can get the full Json document back  
> Yes, this is where I saw what both values were in the search result. I just  
> wanted to stay "inside the API" and not  
> start to interpret the json of the search result myself. But if it has to  
> be...

BR - Martin

On Thursday, January 30, 2014 6:01:38 PM UTC+1, David Pilato wrote:

> I guess you did not ask for specific fields in your query so only \_source  
> is returned by default.
> 
> You can get the full Json document back. Have a look at  
> [https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L392](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L392)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 30 janvier 2014 at 11:27:18, Martin Pape ([pape....@gmail.com](mailto:pape....@gmail.com)\<javascript:\>)  
> a écrit:
> 
> Hi,
> 
> the json (logged with SearchResponse.toString()) of my search result  
> looks like this:  
> ...  
> "title": "abc, cdf Systemfunktionen",  
> \* "type": [\*
> 
> - 
> 
> ```
> "abc",*
> 
> ```
> 
> - 
> 
> ```
> "cdf"*
> 
> ```
> 
> - 
> 
> ```
> ]*
> ...
> 
> ```
> 
> so field: type is an array of 2 values.  
> Then in  
> SearchHitField.getValues().size()  
> I get only 1.  
> How to get both values "abc" and "cdf" from the SearchHitField so  
> SearchHitField.getValues().size() == 2  
> ?
> 
> Please advice and many thanks in advance!
> 
> Martin
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9a1ca261-0527-4c86-861d-52a8258c3d9c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9a1ca261-0527-4c86-861d-52a8258c3d9c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2014, 5:34pm UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/4 "2014-01-30T17:34:42Z")

</div>

If you want only some fields, you can use that: [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java#L415-415](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java#L415-415)

## HTH

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 30 janvier 2014 at 18:08:50, Martin Pape ([pape.martin@gmail.com](mailto:pape.martin@gmail.com)) a écrit:

Hi and thanks for the reply.

> I guess you did not ask for specific fields in your query so only \_source is returned by default.  
> No, I was specifying the fields to return. "type" was one of them.

> You can get the full Json document back  
> Yes, this is where I saw what both values were in the search result. I just wanted to stay "inside the API" and not  
> start to interpret the json of the search result myself. But if it has to be...

BR - Martin

On Thursday, January 30, 2014 6:01:38 PM UTC+1, David Pilato wrote:  
I guess you did not ask for specific fields in your query so only \_source is returned by default.

You can get the full Json document back. Have a look at [hands-on/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java at answers · elasticsearchfr/hands-on · GitHub](https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L392)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 30 janvier 2014 at 11:27:18, Martin Pape ([pape....@gmail.com](mailto:pape....@gmail.com)) a écrit:

Hi,

the json (logged with SearchResponse.toString()) of my search result looks like this:  
...  
"title": "abc, cdf Systemfunktionen",  
"type": [  
"abc",  
"cdf"  
]  
...  
so field: type is an array of 2 values.  
Then in  
SearchHitField.getValues().size()  
I get only 1.  
How to get both values "abc" and "cdf" from the SearchHitField so  
SearchHitField.getValues().size() == 2  
?

Please advice and many thanks in advance!

Martin

## -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/40bdfdac-2583-46cb-ac08-c792afd83d33%40googlegroups.com). For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9a1ca261-0527-4c86-861d-52a8258c3d9c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9a1ca261-0527-4c86-861d-52a8258c3d9c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.52ea8d33.2ca88611.45fa%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52ea8d33.2ca88611.45fa%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 30, 2014, 5:54pm UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/5 "2014-01-30T17:54:58Z")

</div>

Martin, I have verified this behavior and it still pesists in 0.90.10. I  
checked the latest ES master build at it indeed returns 2 values in the  
List as expected so I am expecting it to behave as you expect in ES 1.0.  
For now, what it does is it returns a single item inside the List, but that  
item is in turn an ArrayList of 2 String values. If you have only 1 value,  
it returns a single item in the List, and that item is a String. So you can  
test accordingly in code to check if the value is a String or an ArrayList  
and then adjust accordingly. Should be rectified in 1.0 I hope. 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9e94f706-ad64-4414-91eb-152b48deb5bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9e94f706-ad64-4414-91eb-152b48deb5bf%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Martin\_Pape](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@Martin\_Pape](https://discuss.elastic.co/u/Martin_Pape)\
**Post date:** [January 30, 2014, 10:23pm UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/6 "2014-01-30T22:23:04Z")

</div>

Thanks for the information. I still have some months till production, so  
might workaround now and wait for ES 1.0. Anyone know then ES 1.0 is  
planned to be release?

BR - Martin

On Thursday, January 30, 2014 6:54:58 PM UTC+1, Binh Ly wrote:

> Martin, I have verified this behavior and it still pesists in 0.90.10. I  
> checked the latest ES master build at it indeed returns 2 values in the  
> List as expected so I am expecting it to behave as you expect in ES 1.0.  
> For now, what it does is it returns a single item inside the List, but that  
> item is in turn an ArrayList of 2 String values. If you have only 1 value,  
> it returns a single item in the List, and that item is a String. So you can  
> test accordingly in code to check if the value is a String or an ArrayList  
> and then adjust accordingly. Should be rectified in 1.0 I hope. 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/963d65b0-e5d3-4931-8a0b-85d6fb5c1910%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/963d65b0-e5d3-4931-8a0b-85d6fb5c1910%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Martin\_Pape](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@Martin\_Pape](https://discuss.elastic.co/u/Martin_Pape)\
**Post date:** [June 13, 2014, 8:11am UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/7 "2014-06-13T08:11:44Z")

</div>

I've tested it with ES 1.1 and the described behaviour is gone. So the Java  
API does a correct interpretation of the JSON search result.

On Thursday, January 30, 2014 11:23:04 PM UTC+1, Martin Pape wrote:

> Thanks for the information. I still have some months till production, so  
> might workaround now and wait for ES 1.0. Anyone know then ES 1.0 is  
> planned to be release?
> 
> BR - Martin
> 
> On Thursday, January 30, 2014 6:54:58 PM UTC+1, Binh Ly wrote:
> 
> > Martin, I have verified this behavior and it still pesists in 0.90.10. I  
> > checked the latest ES master build at it indeed returns 2 values in the  
> > List as expected so I am expecting it to behave as you expect in ES 1.0.  
> > For now, what it does is it returns a single item inside the List, but that  
> > item is in turn an ArrayList of 2 String values. If you have only 1 value,  
> > it returns a single item in the List, and that item is a String. So you can  
> > test accordingly in code to check if the value is a String or an ArrayList  
> > and then adjust accordingly. Should be rectified in 1.0 I hope. 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5bc24d1a-d696-4bc5-97bd-86f6780cd4f4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5bc24d1a-d696-4bc5-97bd-86f6780cd4f4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:22am UTC](https://discuss.elastic.co/t/java-api-es-0-90-9-array-2-elements-in-search-result-gets-only-one-value-in-searchhitfield-getvalues/15495/8 "2017-07-06T01:22:48Z")

</div>


