Get the values of a field from all the documents


(Isra) #1

I'm trying to get the values of a field from all the documents. I tried the following without setting the id, in hopes that it would returns all the results, however, it objected and gave an error that I had to set the ID, which resulted in returning the value of just one field that has that id that I had specified:

GetResponse response = NodeClient().prepareGet().setIndex("index-name")
               .setType("user").setId("1")
               .setFields("id").execute().actionGet();
GetField field = response.getField("id");
result = field.getValues();

How can I return a list of all the values of a field from all the documents I have in an index?

Thank you.


(Isra) #2

Im assuming I need to use field.iterator().next(). Just not sure how, it's not giving me the result I'm looking for.


(system) #3