Get nested object fields with java api, addfields doesnt work

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

1 Like

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

1 Like