# Getting all the distinct values of a field

**URL:** <https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437>\
**Category:** Elasticsearch\
**Created:** [January 19, 2012, 8:13am UTC](https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437 "2012-01-19T08:13:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [January 19, 2012, 8:13am UTC](https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437/1 "2012-01-19T08:13:14Z")

</div>

Hi Team,

One of our use cases is to get all the distinct values of a particular field. For e. g. if we are querying against Oracle database we can execute below query :

select distinct column\_name from table\_name

The above query gives us all the distinct values of column 'column\_name' from the table 'table\_name'.

We need something similar in Elastic Search. Please provide inputs on how this can be achieved in Elastic Search Java API.

Thanks..

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [January 19, 2012, 9:40am UTC](https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437/2 "2012-01-19T09:40:21Z")

</div>

If the column\_name is indexed with a keyword analyzer then you can  
facet over that field:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Peter.

On 19 Jan., 09:13, ElasticUsers [kranti\_...@rediffmail.com](mailto:kranti_...@rediffmail.com) wrote:

> Hi Team,
> 
> One of our use cases is to get all the distinct values of a particular  
> field. For e. g. if we are querying against Oracle database we can execute  
> below query :
> 
> select distinct column\_name from table\_name
> 
> The above query gives us all the distinct values of column 'column\_name'  
> from the table 'table\_name'.
> 
> We need something similar in Elastic Search. Please provide inputs on how  
> this can be achieved in Elastic Search Java API.
> 
> Thanks..
> 
> --  
> View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Getting-all-the-disti](http://elasticsearch-users.115913.n3.nabble.com/Getting-all-the-disti)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 20, 2012, 5:43am UTC](https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437/3 "2012-01-20T05:43:00Z")

</div>

There was a discussion about this functionality not too long ago and  
an issue was opened:

> <https://github.com/elastic/elasticsearch/issues/1530>
>
> Currently terms facet has an option all\_terms which is expected to bring all the… terms in the index (for a
> field) with frequency counts on them. However, it does not work. Can you fix this?
> 
> Discussed in 
> http://elasticsearch-users.115913.n3.nabble.com/Terms-facet-all-terms-does-not-work-td3568708.html

On Thu, Jan 19, 2012 at 1:40 AM, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com) wrote:

> If the column\_name is indexed with a keyword analyzer then you can  
> facet over that field:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)
> 
> Peter.
> 
> On 19 Jan., 09:13, ElasticUsers [kranti\_...@rediffmail.com](mailto:kranti_...@rediffmail.com) wrote:
> 
> > Hi Team,
> > 
> > One of our use cases is to get all the distinct values of a particular  
> > field. For e. g. if we are querying against Oracle database we can execute  
> > below query :
> > 
> > select distinct column\_name from table\_name
> > 
> > The above query gives us all the distinct values of column 'column\_name'  
> > from the table 'table\_name'.
> > 
> > We need something similar in Elastic Search. Please provide inputs on how  
> > this can be achieved in Elastic Search Java API.
> > 
> > Thanks..
> > 
> > --  
> > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Getting-all-the-disti](http://elasticsearch-users.115913.n3.nabble.com/Getting-all-the-disti)...  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Patricia\_Narvasa](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@Patricia\_Narvasa](https://discuss.elastic.co/u/Patricia_Narvasa)\
**Post date:** [May 4, 2017, 8:44am UTC](https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437/4 "2017-05-04T08:44:20Z")

</div>

Hi all just want to ask if what if the unique values that im currently querying distinct values on ES has special characters.

example:

"user090@sample.com"

it doesn't get the exact value, it gets the count separately for user090, sample, com

---

<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, 10:00pm UTC](https://discuss.elastic.co/t/getting-all-the-distinct-values-of-a-field/6437/5 "2017-07-05T22:00:37Z")

</div>


