# Returning Field Data Inside Aggregation Buckets

**URL:** <https://discuss.elastic.co/t/returning-field-data-inside-aggregation-buckets/17648>\
**Category:** Elasticsearch\
**Created:** [May 21, 2014, 4:58pm UTC](https://discuss.elastic.co/t/returning-field-data-inside-aggregation-buckets/17648 "2014-05-21T16:58:58Z")\
**Posts on this page:** 2\
**Page:** 1

<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 21, 2014, 4:58pm UTC](https://discuss.elastic.co/t/returning-field-data-inside-aggregation-buckets/17648/1 "2014-05-21T16:58:58Z")

</div>

I have big dilemma. Try as I might I can not find a better solution to my  
problem despite my Google foo.

I have a rather large data set that has field values that I need to get the  
distinct values for. I can currently do this either by doing a nested  
aggregation and processing the output (grossly inefficient and takes a long  
time). The other way I can do it is to do just the first level aggregation  
and then do a separate query using the value in each "key" that are  
returned. Also not the most efficient when you are talking about hundreds  
of thousands of unique values.

For the sake of explanation lets say I have a very large data set of  
employees. Among the dozen or so other fields there is an EMPLOYEE\_ID,  
FIRST\_NAME & LAST\_NAME.

Is there any way to do an aggregation/facet on just to get the distinct  
EMPLOYEE\_ID's and also just bring back the value of FIRST\_NAME & LAST\_NAME  
as well without all the extra nonsense?

Thanks.

--  
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/9de8fb6d-9f69-41f9-8d95-60e4d1454b3a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9de8fb6d-9f69-41f9-8d95-60e4d1454b3a%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:27am UTC](https://discuss.elastic.co/t/returning-field-data-inside-aggregation-buckets/17648/2 "2017-07-06T01:27:50Z")

</div>


