Get nested object fields with java api, addfields doesnt work

(makovskij) #1


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)
.setQuery(QueryBuilders.termQuery("name", andi))

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?


(Jason Wee) #2

how about adresses.street?

(system) #3