# Proper use of aggregation?

**URL:** <https://discuss.elastic.co/t/proper-use-of-aggregation/16357>\
**Category:** Elasticsearch\
**Created:** [March 13, 2014, 5:46pm UTC](https://discuss.elastic.co/t/proper-use-of-aggregation/16357 "2014-03-13T17:46:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tinou\_Bao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tinou_bao/32/1736_2.png) [@Tinou\_Bao](https://discuss.elastic.co/u/Tinou_Bao)\
**Post date:** [March 13, 2014, 5:46pm UTC](https://discuss.elastic.co/t/proper-use-of-aggregation/16357/1 "2014-03-13T17:46:41Z")

</div>

My instincts says this is not the proper use of aggregation but want to  
check w/ people who have actually used it. We want to bucket on a very high  
cardinality field and return **ALL** buckets (no size limit). For example,  
imagine documents representing people and their parents:

# person - parent

john - cindy  
james - cindy  
tony - mark  
tim - doug

I want to bucket by parent, so it'll be

cindy

- john
- james  
mark
- tony  
doug
- tim

This is a high cardinality field, so already it concerns me. I want all  
buckets (setting size to zero). So if I have 10,000 documents I have 5,000  
parent buckets and I want all 5,000 of these parent buckets. Essentially  
I'm trying to display by parent (group by parent). Moreover, I want to sort  
the parent's age (so imagine the parent has an age it it). Or maybe I want  
to sort by the average person (child) age in each bucket. So w/ aggregation  
this seems possible:

bucket by parent, sort by average age of person, bucket by person (to get  
all people for a parent bucket), set size to zero.

But it feels very wrong to me, both in terms of the potential performance  
issues around unlimited, high cardinality buckets and the sorting of those  
buckets; and that aggregration/bucketing wasn't designed for this.

Any input/feedback would be appreciated.  
-T

--  
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/ea6665a1-6562-456c-a806-937fd9f15463%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ea6665a1-6562-456c-a806-937fd9f15463%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:43am UTC](https://discuss.elastic.co/t/proper-use-of-aggregation/16357/2 "2017-07-06T01:43:23Z")

</div>


