# Return unique records for a certain field

**URL:** <https://discuss.elastic.co/t/return-unique-records-for-a-certain-field/12216>\
**Category:** Elasticsearch\
**Created:** [June 1, 2013, 7:48am UTC](https://discuss.elastic.co/t/return-unique-records-for-a-certain-field/12216 "2013-06-01T07:48:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_MZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_mz/32/2215_2.png) [@David\_MZ](https://discuss.elastic.co/u/David_MZ)\
**Post date:** [June 1, 2013, 7:48am UTC](https://discuss.elastic.co/t/return-unique-records-for-a-certain-field/12216/1 "2013-06-01T07:48:23Z")

</div>

I have the following problem, I have a document say

foo {  
bar:1  
--other fields--  
}

I want to call a query that will return results based on other fields but  
with bar been unique at the result set, meaning if there are more then 1  
document matching the query that has bar == 1 I want to return only 1  
results, say the first result.

This is like doing a group by and only taking the first record at the each  
group

How can I do this in Elastic?

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 3, 2013, 7:20pm UTC](https://discuss.elastic.co/t/return-unique-records-for-a-certain-field/12216/2 "2013-06-03T19:20:44Z")

</div>

From what I can understand, you are probably looking for something like  
field collapsing, which is not (yet?) implemented in elasticsearch.

Can you provide an pseudo-example with a sample document and query?

--  
Ivan

On Sat, Jun 1, 2013 at 12:48 AM, David MZ [david.mazvovsky@gmail.com](mailto:david.mazvovsky@gmail.com) wrote:

> I have the following problem, I have a document say
> 
> foo {  
> bar:1  
> --other fields--  
> }
> 
> I want to call a query that will return results based on other fields but  
> with bar been unique at the result set, meaning if there are more then 1  
> document matching the query that has bar == 1 I want to return only 1  
> results, say the first result.
> 
> This is like doing a group by and only taking the first record at the each  
> group
> 
> How can I do this in Elastic?
> 
> --  
> 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).

--  
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:33am UTC](https://discuss.elastic.co/t/return-unique-records-for-a-certain-field/12216/3 "2017-07-06T02:33:14Z")

</div>


