# Returning only unique results

**URL:** <https://discuss.elastic.co/t/returning-only-unique-results/17738>\
**Category:** Elasticsearch\
**Created:** [May 27, 2014, 4:39am UTC](https://discuss.elastic.co/t/returning-only-unique-results/17738 "2014-05-27T04:39:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seja12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seja12/32/115567_2.png) [@seja12](https://discuss.elastic.co/u/seja12)\
**Post date:** [May 27, 2014, 4:39am UTC](https://discuss.elastic.co/t/returning-only-unique-results/17738/1 "2014-05-27T04:39:22Z")

</div>

Is there someway in elasticsearch to adapt the following query so that it  
only produces unique results. For example I have the following data:

## Name | Age | Height

John | 10 | 4'6  
John | 11 | 4'8  
John | 12 | 4'10  
John | 12 | 4'11  
Adam | 12 | 4'12

I want to adjust the following query:

{  
"query": {  
"match\_all": {}  
},  
"terms": {  
"field": "name"  
}  
}

So that it returns the following:

## Name | Age | Height

John | 12 | 4'11  
Adam | 12 | 4'12

Also, how can I adjust it to group by two fields?

--  
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/571309b4-05df-4a08-b90e-6a9cb115021f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/571309b4-05df-4a08-b90e-6a9cb115021f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ES\_USER1](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@ES\_USER1](https://discuss.elastic.co/u/ES_USER1)\
**Post date:** [May 27, 2014, 12:36pm UTC](https://discuss.elastic.co/t/returning-only-unique-results/17738/2 "2014-05-27T12:36:49Z")

</div>

This is similar to the question I asked last week.

[https://groups.google.com/forum/#!topic/elasticsearch/w4C1m1u55FA](https://groups.google.com/forum/#!topic/elasticsearch/w4C1m1u55FA)

On Tuesday, May 27, 2014 12:39:22 AM UTC-4, John wrote:

> Is there someway in elasticsearch to adapt the following query so that it  
> only produces unique results. For example I have the following data:
> 
> ## Name | Age | Height
> 
> John | 10 | 4'6  
> John | 11 | 4'8  
> John | 12 | 4'10  
> John | 12 | 4'11  
> Adam | 12 | 4'12
> 
> I want to adjust the following query:
> 
> {  
> "query": {  
> "match\_all": {}  
> },  
> "terms": {  
> "field": "name"  
> }  
> }
> 
> So that it returns the following:
> 
> ## Name | Age | Height
> 
> John | 12 | 4'11  
> Adam | 12 | 4'12
> 
> Also, how can I adjust it to group by two fields?

--  
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/b1ebc645-610f-4f66-a572-01e7e5cbb597%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b1ebc645-610f-4f66-a572-01e7e5cbb597%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [May 28, 2014, 3:16am UTC](https://discuss.elastic.co/t/returning-only-unique-results/17738/3 "2014-05-28T03:16:18Z")

</div>

Perhaps the top hits aggregation coming in 1.3 could help:

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

--  
Ivan

On Tue, May 27, 2014 at 5:36 AM, ES USER [es.user.2014@gmail.com](mailto:es.user.2014@gmail.com) wrote:

> This is similar to the question I asked last week.
> 
> [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/elasticsearch/w4C1m1u55FA)
> 
> On Tuesday, May 27, 2014 12:39:22 AM UTC-4, John wrote:
> 
> > Is there someway in elasticsearch to adapt the following query so that it  
> > only produces unique results. For example I have the following data:
> > 
> > ## Name | Age | Height
> > 
> > John | 10 | 4'6  
> > John | 11 | 4'8  
> > John | 12 | 4'10  
> > John | 12 | 4'11  
> > Adam | 12 | 4'12
> > 
> > I want to adjust the following query:
> > 
> > {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "terms": {  
> > "field": "name"  
> > }  
> > }
> > 
> > So that it returns the following:
> > 
> > ## Name | Age | Height
> > 
> > John | 12 | 4'11  
> > Adam | 12 | 4'12
> > 
> > Also, how can I adjust it to group by two fields?
> > 
> > --  
> > 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/b1ebc645-610f-4f66-a572-01e7e5cbb597%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b1ebc645-610f-4f66-a572-01e7e5cbb597%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/b1ebc645-610f-4f66-a572-01e7e5cbb597%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b1ebc645-610f-4f66-a572-01e7e5cbb597%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CALY%3DcQCAQjz%2BccnKHfixSVTUwQGefTh0ZUmMo48JTq0C%3DNP%3D9Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCAQjz%2BccnKHfixSVTUwQGefTh0ZUmMo48JTq0C%3DNP%3D9Q%40mail.gmail.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:26am UTC](https://discuss.elastic.co/t/returning-only-unique-results/17738/4 "2017-07-06T01:26:29Z")

</div>


