# How to retrieve all unique values from a given field

**URL:** <https://discuss.elastic.co/t/how-to-retrieve-all-unique-values-from-a-given-field/247312>\
**Category:** Elastic Tips and Common Fixes\
**Tags:** elasticsearch\
**Created:** [September 3, 2020, 1:43am UTC](https://discuss.elastic.co/t/how-to-retrieve-all-unique-values-from-a-given-field/247312 "2020-09-03T01:43:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 3, 2020, 1:43am UTC](https://discuss.elastic.co/t/how-to-retrieve-all-unique-values-from-a-given-field/247312/1 "2020-09-03T01:43:37Z")

</div>

The quickest way to do this is to run a zero size, terms aggregation on the field.

Using the Kibana [sample log data](https://www.elastic.co/guide/en/kibana/current/tutorial-sample-data.html) set as an example, you would run;

```auto
GET kibana_sample_data_logs/_search
{
  "size": "0",
  "aggs": {
    "unique_values": {
      "terms": {
        "field": "agent.keyword"
      }
    }
  }
}

```

Which returns;

> **(Expand this for the Elasticsearch response)**
>
> ```auto
> {
> "took" : 4,
> "timed_out" : false,
> "_shards" : {
> "total" : 1,
> "successful" : 1,
> "skipped" : 0,
> "failed" : 0
> },
> "hits" : {
> "total" : {
> "value" : 10000,
> "relation" : "gte"
> },
> "max_score" : null,
> "hits" : []
> },
> "aggregations" : {
> "unique_values" : {
> "doc_count_error_upper_bound" : 0,
> "sum_other_doc_count" : 0,
> "buckets" : [
> {
> "key" : "Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1",
> "doc_count" : 5362
> },
> {
> "key" : "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24",
> "doc_count" : 4702
> },
> {
> "key" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
> "doc_count" : 4010
> }
> ]
> }
> }
> }
> 
> ```

---

<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 4, 2022, 8:12am UTC](https://discuss.elastic.co/t/how-to-retrieve-all-unique-values-from-a-given-field/247312/2 "2022-11-04T08:12:20Z")

</div>


