# How to fetch the distinct records from Elastic Search

**URL:** <https://discuss.elastic.co/t/how-to-fetch-the-distinct-records-from-elastic-search/14584>\
**Category:** Elasticsearch\
**Created:** [November 25, 2013, 7:31pm UTC](https://discuss.elastic.co/t/how-to-fetch-the-distinct-records-from-elastic-search/14584 "2013-11-25T19:31:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sowjanya](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@sowjanya](https://discuss.elastic.co/u/sowjanya)\
**Post date:** [November 25, 2013, 7:31pm UTC](https://discuss.elastic.co/t/how-to-fetch-the-distinct-records-from-elastic-search/14584/1 "2013-11-25T19:31:55Z")

</div>

How to fetch the distinct records from Elastic Search.  
Eg:  
field1 field2 field3  
1 abc xyz  
2 abc def  
3 abc pqr  
Now,iam searhing for xyz OR def OR pqr.  
For these records field2 value is same.  
now,Iam getting the 3 records(abc,abc,abc). But,I need only one  
record(abc). Without iterating the searchHits.  
In SearchHits it should consists only distinct records.

How,can i query for getting the distinct Results.

Please help me.  
Thanks in Advance.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [November 25, 2013, 7:44pm UTC](https://discuss.elastic.co/t/how-to-fetch-the-distinct-records-from-elastic-search/14584/2 "2013-11-25T19:44:59Z")

</div>

Take a look at facets. As long as, your data is indexed appropriately, it  
will give you roll up counts of values for each field specified for a  
query.

Best Regards,  
Paul

On Monday, November 25, 2013 2:31:55 PM UTC-5, Elastic Sowjanya wrote:

> How to fetch the distinct records from Elastic Search.  
> Eg:  
> field1 field2 field3  
> 1 abc xyz  
> 2 abc def  
> 3 abc pqr  
> Now,iam searhing for xyz OR def OR pqr.  
> For these records field2 value is same.  
> now,Iam getting the 3 records(abc,abc,abc). But,I need only one  
> record(abc). Without iterating the searchHits.  
> In SearchHits it should consists only distinct records.
> 
> How,can i query for getting the distinct Results.
> 
> Please help me.  
> Thanks in Advance.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:04am UTC](https://discuss.elastic.co/t/how-to-fetch-the-distinct-records-from-elastic-search/14584/3 "2017-07-06T02:04:53Z")

</div>


