# Get all unique values of a field across documents

**URL:** <https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882>\
**Category:** Elasticsearch\
**Created:** [October 16, 2019, 4:13pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882 "2019-10-16T16:13:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![decodeit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/decodeit/32/46023_2.png) [@decodeit](https://discuss.elastic.co/u/decodeit)\
**Post date:** [October 16, 2019, 4:13pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/1 "2019-10-16T16:13:05Z")

</div>

so i have a field named subjects, it is an array. so I want to get all the values of subjects field in a particular index. should be about 300-400. Can someone suggest how to achieve this.

I am doing this:  
`GET /index/_search { "size": "0", "aggs":{ "by_subjects":{ "terms": { "field": "subjects.en.keyword" } } } }`

but this is returning me only 10 items in a list.  
also its giving me this in result if it helps:  
`"aggregations" : { "by_subjects" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 381,`

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 18, 2019, 9:19am UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/2 "2019-10-18T09:19:43Z")

</div>

Use the `size` parameter to ask for more. Given you have hundreds, not tens of thousands of values, these can all be returned from a single request (otherwise you'd need to use something like the `composite` aggregation to page through results).

---

<div class="post-metadata">

**Author:** ![decodeit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/decodeit/32/46023_2.png) [@decodeit](https://discuss.elastic.co/u/decodeit)\
**Post date:** [October 18, 2019, 12:01pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/3 "2019-10-18T12:01:31Z")

</div>

hello,  
making the size parameter to 400 (keeping rest same) gives me all the documents I have stored in the index.  
my goal is to get all the values of the particular field.  
Thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 18, 2019, 12:12pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/4 "2019-10-18T12:12:11Z")

</div>

Sorry, I wasn't clear. I meant [the size setting inside the terms aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-size).

---

<div class="post-metadata">

**Author:** ![decodeit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/decodeit/32/46023_2.png) [@decodeit](https://discuss.elastic.co/u/decodeit)\
**Post date:** [October 18, 2019, 12:49pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/5 "2019-10-18T12:49:03Z")

</div>

I did try that before and just now as well. its still seems to give me same results, giving me all the documents in the index. Is there anything I am missing. this is my query .

```
`GET /index/_search 

```

{

"aggs":{  
"by\_subjects":{  
"terms":{  
"field": "subjects.en.keyword",  
"size": "5"  
}  
}  
}  
}`

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 18, 2019, 12:54pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/6 "2019-10-18T12:54:17Z")

</div>

![Console_-_Kibana](https://us1.discourse-cdn.com/elastic/original/3X/c/a/cab82bf5d36a25aa6ca1ade4f08a30d355470abd.png)

---

<div class="post-metadata">

**Author:** ![decodeit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/decodeit/32/46023_2.png) [@decodeit](https://discuss.elastic.co/u/decodeit)\
**Post date:** [October 18, 2019, 1:02pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/7 "2019-10-18T13:02:55Z")

</div>

Thanks a lot. This solved the issue.

---

<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:** [November 15, 2019, 1:03pm UTC](https://discuss.elastic.co/t/get-all-unique-values-of-a-field-across-documents/203882/8 "2019-11-15T13:03:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
