# Term aggregation not returning all unique values

**URL:** <https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291>\
**Category:** Elasticsearch\
**Created:** [March 28, 2019, 9:50am UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291 "2019-03-28T09:50:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanthkadem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthkadem/32/40018_2.png) [@srikanthkadem](https://discuss.elastic.co/u/srikanthkadem)\
**Post date:** [March 28, 2019, 9:50am UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/1 "2019-03-28T09:50:20Z")

</div>

Hi ,

I am using Term Aggregations to get unique values for fields to show them as filters. however I am not getting all the results from ES.  
code .  
`GET /_search { "aggs" : { "genres" : { "terms" : { "field" : "TEST_CountryArray.keyword" } } } }`  
output..  
`China Andorra Germany Algeria Brazil Afghanistan Angola Australia Austria Cyprus`

but I know that I have job with UK(in capital lettlers, not sure if thats an issue) in countries list which is inserted to ES later point of time.  
query:  
`GET jobs/\_search  
{

```
"query":{"bool":{"must":[{"term":{"TEST_CountryArray.keyword":"UK"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}

```

}`  
PFB for query result.  
in terms query...

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/e/cee0819aaed57eab7aaf8918edff771ae82c7b4f.png)  
..in Terms aggregation  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/b/0b81f71396152fa5a29824d56407e1a321b4aadb.png)  
can someone explain what could be the issue, and need any additional info.

Regards,  
Srikanth

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 28, 2019, 10:17am UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/2 "2019-03-28T10:17:14Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![srikanthkadem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthkadem/32/40018_2.png) [@srikanthkadem](https://discuss.elastic.co/u/srikanthkadem)\
**Post date:** [March 28, 2019, 11:14am UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/3 "2019-03-28T11:14:42Z")

</div>

Thanks @dadoonet for the response. I am using NEST client from Dotnet to interact with ES and not much familiar with direct ES queries(I have posted the request output given by NEST). Can I share Nest code to get more details on this.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 28, 2019, 12:00pm UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/4 "2019-03-28T12:00:07Z")

</div>

> [@srikanthkadem](#):
>
> Can I share Nest code to get more details on this.

You can but I won't be able to help then.  
Just open Kibana dev console and try to reproduce your problem without Nest and then we can see what is going wrong, how to fix, which you'll be able to translate to nest.

---

<div class="post-metadata">

**Author:** ![srikanthkadem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthkadem/32/40018_2.png) [@srikanthkadem](https://discuss.elastic.co/u/srikanthkadem)\
**Post date:** [March 29, 2019, 1:11pm UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/5 "2019-03-29T13:11:26Z")

</div>

Hey @dadoonet..I just updated with full query information and screenshots from Kibana..can you please have a look and see where I am doing wrong.

---

<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:** [March 29, 2019, 1:30pm UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/6 "2019-03-29T13:30:20Z")

</div>

By default you only get the top 10 terms (and the UK is not in that top ten).  
Set the terms agg `size` parameter to a larger number to see more

---

<div class="post-metadata">

**Author:** ![srikanthkadem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanthkadem/32/40018_2.png) [@srikanthkadem](https://discuss.elastic.co/u/srikanthkadem)\
**Post date:** [March 29, 2019, 1:50pm UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/7 "2019-03-29T13:50:06Z")

</div>

Yeah. That really helped @Mark_Harwood. I was using global size parameter(size to specify docs count) that returns documents not terms. I just used size parameter for term it worked perfectly.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/b/9b4ce71aaf3221ca83747d88395de0ab4a027f3b.png)

---

<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:** [April 26, 2019, 1:50pm UTC](https://discuss.elastic.co/t/term-aggregation-not-returning-all-unique-values/174291/8 "2019-04-26T13:50:07Z")

</div>

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