# Unique/Distinct values from elasticsearch query

**URL:** <https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890>\
**Category:** Elasticsearch\
**Created:** [February 19, 2014, 9:51am UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890 "2014-02-19T09:51:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumya\_sengupta](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@soumya\_sengupta](https://discuss.elastic.co/u/soumya_sengupta)\
**Post date:** [February 19, 2014, 9:51am UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/1 "2014-02-19T09:51:35Z")

</div>

How to get unique or distinct values from elastic search query ?  
I want to get all the unique vales and not their total count.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![aash\_dhariya](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@aash\_dhariya](https://discuss.elastic.co/u/aash_dhariya)\
**Post date:** [February 19, 2014, 11:06am UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/2 "2014-02-19T11:06:13Z")

</div>

You could use facet query to get all the unique values for a particular  
field. Though you will get the counts too.

On Wed, Feb 19, 2014 at 3:21 PM, soumya sengupta  
[maverick.soumya@gmail.com](mailto:maverick.soumya@gmail.com)wrote:

> How to get unique or distinct values from Elasticsearch query ?  
> I want to get all the unique vales and not their total count.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Thanks,  
Aash

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAG7ZG\_c9dFktpJ%2BucLQpmQp-oYqssKhBc9bfg%3D%2B-DA3vEK\_4YA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAG7ZG_c9dFktpJ%2BucLQpmQp-oYqssKhBc9bfg%3D%2B-DA3vEK_4YA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![soumya\_sengupta](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@soumya\_sengupta](https://discuss.elastic.co/u/soumya_sengupta)\
**Post date:** [February 19, 2014, 11:32am UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/3 "2014-02-19T11:32:57Z")

</div>

I have got an ngram-analyzer for the field which is preventing me from  
using facets.  
What options do I have ?

On Wednesday, February 19, 2014 4:36:13 PM UTC+5:30, geeky\_sh wrote:

> You could use facet query to get all the unique values for a particular  
> field. Though you will get the counts too.
> 
> On Wed, Feb 19, 2014 at 3:21 PM, soumya sengupta \<[maveric...@gmail.com](mailto:maveric...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > How to get unique or distinct values from Elasticsearch query ?  
> > I want to get all the unique vales and not their total count.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Thanks,  
> Aash

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![aash\_dhariya](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@aash\_dhariya](https://discuss.elastic.co/u/aash_dhariya)\
**Post date:** [February 19, 2014, 12:11pm UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/4 "2014-02-19T12:11:06Z")

</div>

You can set the type of the field as multi\_field. For example:

"value" : {  
"type" : "multi\_field",  
"fields" : {  
"value" : {  
"type" : "string",  
"analyzer" : "custom\_ngram\_analyzer"  
},  
"value\_untouched" : {  
"type" : "string",  
"index" : "not\_analyzed",  
}  
}  
}

Now, you can compute the facets for value.value\_untouched and for search  
you can simple use value.

To learn more about multi\_field, you can visit:

> **[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.

On Wed, Feb 19, 2014 at 5:02 PM, soumya sengupta  
[maverick.soumya@gmail.com](mailto:maverick.soumya@gmail.com)wrote:

> I have got an ngram-analyzer for the field which is preventing me from  
> using facets.  
> What options do I have ?
> 
> On Wednesday, February 19, 2014 4:36:13 PM UTC+5:30, geeky\_sh wrote:
> 
> > You could use facet query to get all the unique values for a particular  
> > field. Though you will get the counts too.
> > 
> > On Wed, Feb 19, 2014 at 3:21 PM, soumya sengupta [maveric...@gmail.com](mailto:maveric...@gmail.com)wrote:
> > 
> > > How to get unique or distinct values from Elasticsearch query ?  
> > > I want to get all the unique vales and not their total count.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%  
> > > [40googlegroups.com](http://40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > Thanks,  
> > Aash
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Thanks,  
Aash

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAG7ZG\_fgm2DV1paXe\_OiH7fcKPe0M3bYA8Jr7VMHqxiqZFtmNA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAG7ZG_fgm2DV1paXe_OiH7fcKPe0M3bYA8Jr7VMHqxiqZFtmNA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![soumya\_sengupta](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@soumya\_sengupta](https://discuss.elastic.co/u/soumya_sengupta)\
**Post date:** [February 20, 2014, 7:09am UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/5 "2014-02-20T07:09:08Z")

</div>

Thanks, that worked

On Wed, Feb 19, 2014 at 5:41 PM, aash dhariya [aash.discover@gmail.com](mailto:aash.discover@gmail.com)wrote:

> You can set the type of the field as multi\_field. For example:
> 
> "value" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "value" : {  
> "type" : "string",  
> "analyzer" : "custom\_ngram\_analyzer"  
> },  
> "value\_untouched" : {  
> "type" : "string",  
> "index" : "not\_analyzed",  
> }  
> }  
> }
> 
> Now, you can compute the facets for value.value\_untouched and for search  
> you can simple use value.
> 
> To learn more about multi\_field, you can visit:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/mapping-multi-field-type.html)
> 
> On Wed, Feb 19, 2014 at 5:02 PM, soumya sengupta \<  
> [maverick.soumya@gmail.com](mailto:maverick.soumya@gmail.com)\> wrote:
> 
> > I have got an ngram-analyzer for the field which is preventing me from  
> > using facets.  
> > What options do I have ?
> > 
> > On Wednesday, February 19, 2014 4:36:13 PM UTC+5:30, geeky\_sh wrote:
> > 
> > > You could use facet query to get all the unique values for a particular  
> > > field. Though you will get the counts too.
> > > 
> > > On Wed, Feb 19, 2014 at 3:21 PM, soumya sengupta [maveric...@gmail.com](mailto:maveric...@gmail.com)wrote:
> > > 
> > > > How to get unique or distinct values from Elasticsearch query ?  
> > > > I want to get all the unique vales and not their total count.
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%  
> > > > [40googlegroups.com](http://40googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > Thanks,  
> > > Aash
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Thanks,  
> Aash
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/VL0Zn9kXzbk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/VL0Zn9kXzbk/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAG7ZG\_fgm2DV1paXe\_OiH7fcKPe0M3bYA8Jr7VMHqxiqZFtmNA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAG7ZG_fgm2DV1paXe_OiH7fcKPe0M3bYA8Jr7VMHqxiqZFtmNA%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Soumya Sen Gupta

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAOzQMVQt%2Ba6gq73Y35nunP7MKGTj3EEB1%2B%3Dfpirg5c%2BAxDpxMg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOzQMVQt%2Ba6gq73Y35nunP7MKGTj3EEB1%2B%3Dfpirg5c%2BAxDpxMg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jigish\_thakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jigish_thakar/32/753_2.png) [@jigish\_thakar](https://discuss.elastic.co/u/jigish_thakar)\
**Post date:** [July 17, 2014, 12:10pm UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/6 "2014-07-17T12:10:21Z")

</div>

Hey Soumya,  
I needed exactly same in my implementation. and hardly 2 days old with  
Elasticsearch.

Can you please post code snippet you used in mapping and then to fetch  
unique values?

Thanks in advance.

On Thursday, February 20, 2014 12:39:08 PM UTC+5:30, soumya sengupta wrote:

> Thanks, that worked
> 
> On Wed, Feb 19, 2014 at 5:41 PM, aash dhariya \<[aash.d...@gmail.com](mailto:aash.d...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > You can set the type of the field as multi\_field. For example:
> > 
> > "value" : {  
> > "type" : "multi\_field",  
> > "fields" : {  
> > "value" : {  
> > "type" : "string",  
> > "analyzer" : "custom\_ngram\_analyzer"  
> > },  
> > "value\_untouched" : {  
> > "type" : "string",  
> > "index" : "not\_analyzed",  
> > }  
> > }  
> > }
> > 
> > Now, you can compute the facets for value.value\_untouched and for search  
> > you can simple use value.
> > 
> > To learn more about multi\_field, you can visit:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/mapping-multi-field-type.html)
> > 
> > On Wed, Feb 19, 2014 at 5:02 PM, soumya sengupta \<[maveric...@gmail.com](mailto:maveric...@gmail.com)  
> > \<javascript:\>\> wrote:
> > 
> > > I have got an ngram-analyzer for the field which is preventing me from  
> > > using facets.  
> > > What options do I have ?
> > > 
> > > On Wednesday, February 19, 2014 4:36:13 PM UTC+5:30, geeky\_sh wrote:
> > > 
> > > > You could use facet query to get all the unique values for a particular  
> > > > field. Though you will get the counts too.
> > > > 
> > > > On Wed, Feb 19, 2014 at 3:21 PM, soumya sengupta [maveric...@gmail.com](mailto:maveric...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > How to get unique or distinct values from Elasticsearch query ?  
> > > > > I want to get all the unique vales and not their total count.
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > 
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/00a45aff-6d67-40ae-8c54-e00481011bce%  
> > > > > [40googlegroups.com](http://40googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > Thanks,  
> > > > Aash
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d798c2f3-c460-45f1-a83a-fcb5180f40c9%40googlegroups.com)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > Thanks,  
> > Aash
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/VL0Zn9kXzbk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/VL0Zn9kXzbk/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAG7ZG\_fgm2DV1paXe\_OiH7fcKPe0M3bYA8Jr7VMHqxiqZFtmNA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAG7ZG_fgm2DV1paXe_OiH7fcKPe0M3bYA8Jr7VMHqxiqZFtmNA%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Soumya Sen Gupta

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/acb62c3d-00d7-4f7a-9b3e-08d64aeb82bf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/acb62c3d-00d7-4f7a-9b3e-08d64aeb82bf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:15am UTC](https://discuss.elastic.co/t/unique-distinct-values-from-elasticsearch-query/15890/7 "2017-07-06T01:15:14Z")

</div>


