# How to create agg bucket over distinct nested objects

**URL:** <https://discuss.elastic.co/t/how-to-create-agg-bucket-over-distinct-nested-objects/25270>\
**Category:** Elasticsearch\
**Created:** [July 9, 2015, 11:38pm UTC](https://discuss.elastic.co/t/how-to-create-agg-bucket-over-distinct-nested-objects/25270 "2015-07-09T23:38:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [July 9, 2015, 11:38pm UTC](https://discuss.elastic.co/t/how-to-create-agg-bucket-over-distinct-nested-objects/25270/1 "2015-07-09T23:38:48Z")

</div>

Hello,

Probably the easiest to explain by example:

I have a meeting with collection of participants (nested mapping). Each Participant is an object consisting of a Person and Company. Very often many people from the same company participate.

Ii need to calculate in how many meetings a company has participated counting only once even if there were many participants for the same company in a meeting. Counting alone i could probably achieve with cardinality aggregation over meeting ID but I also need some other stats (sum) that should not double count and even more so I need to sub aggregate by company department

I guess I could preprocess my documents to add participatingCompanies property with distinct companies and work with it but I would really prefer to avoid polluting my source with such extra fields as it is widely used for various searches, analytics and reporting

I would appreciate your advise

Thanks  
alex

---

<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, 12:02am UTC](https://discuss.elastic.co/t/how-to-create-agg-bucket-over-distinct-nested-objects/25270/2 "2017-07-06T00:02:29Z")

</div>


