# Get the values of a field from all the documents

**URL:** https://discuss.elastic.co/t/get-the-values-of-a-field-from-all-the-documents/37955
**Category:** Elasticsearch
**Created:** [December 24, 2015, 7:51pm UTC](https://discuss.elastic.co/t/get-the-values-of-a-field-from-all-the-documents/37955 "2015-12-24T19:51:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)
#### Post date: [December 24, 2015, 7:51pm UTC](https://discuss.elastic.co/t/get-the-values-of-a-field-from-all-the-documents/37955/1 "2015-12-24T19:51:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Isra](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@Isra](https://discuss.elastic.co/u/Isra)
#### Post date: [December 24, 2015, 10:20pm UTC](https://discuss.elastic.co/t/get-the-values-of-a-field-from-all-the-documents/37955/2 "2015-12-24T22:20:18Z")

</div>

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

---

<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 5, 2017, 11:28pm UTC](https://discuss.elastic.co/t/get-the-values-of-a-field-from-all-the-documents/37955/3 "2017-07-05T23:28:40Z")

</div>


