# Get nested object fields with java api, addfields doesnt work

**URL:** <https://discuss.elastic.co/t/get-nested-object-fields-with-java-api-addfields-doesnt-work/2580>\
**Category:** Elasticsearch\
**Created:** [June 12, 2015, 2:23pm UTC](https://discuss.elastic.co/t/get-nested-object-fields-with-java-api-addfields-doesnt-work/2580 "2015-06-12T14:23:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andimak](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@andimak](https://discuss.elastic.co/u/andimak)\
**Post date:** [June 12, 2015, 2:23pm UTC](https://discuss.elastic.co/t/get-nested-object-fields-with-java-api-addfields-doesnt-work/2580/1 "2015-06-12T14:23:01Z")

</div>

hi,

I have some documents like that with nested objects:

```
_score": 1,
        "_source": {
           "name": "andi",
           "age": "51",
           "adresses": [
              {
                 "town": "berlin",
                 "street": "anystreet",
                 "number": "12",
              },
              {
                 "town": "munich",
                 "street": "anystreet",
                 "number": "12",
              }, ...................

```

I want to get the last "adress" but i can't get the jsonarray with .addfields("adresses") :

> SearchResponse response = client.prepareSearch(yearMonth)  
> .addField("age").addField("name")  
> .addFieldDataField("adresses")  
> .setQuery(QueryBuilders.termQuery("name", andi))  
> .execute().actionGet();

If I use .addFields("street") it doesnt work either.  
So how to get this field? if i remove .addFieldDataField("adresses") it works well and i get the age and name field.

I used a http request and i got all the fields like expected and i could extract it, but i liked to stay with the java client and use the api since i used it for all other requests.  
Can i get just the whole document without any addfields parameter or what is my mistake to get the array?

regards  
andi

---

<div class="post-metadata">

**Author:** ![Jason\_Wee](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jason\_Wee](https://discuss.elastic.co/u/Jason_Wee)\
**Post date:** [June 13, 2015, 10:20pm UTC](https://discuss.elastic.co/t/get-nested-object-fields-with-java-api-addfields-doesnt-work/2580/2 "2015-06-13T22:20:51Z")

</div>

how about adresses.street? [https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/search/innerhits/InnerHitsTests.java#L159](https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/search/innerhits/InnerHitsTests.java#L159)

---

<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, 12:07am UTC](https://discuss.elastic.co/t/get-nested-object-fields-with-java-api-addfields-doesnt-work/2580/3 "2017-07-06T00:07:41Z")

</div>


