# Unable to calculate average bucket over multi layer data

**URL:** https://discuss.elastic.co/t/unable-to-calculate-average-bucket-over-multi-layer-data/273270
**Category:** Elasticsearch
**Created:** [May 18, 2021, 10:56am UTC](https://discuss.elastic.co/t/unable-to-calculate-average-bucket-over-multi-layer-data/273270 "2021-05-18T10:56:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sumit.sontakke](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sumit.sontakke](https://discuss.elastic.co/u/sumit.sontakke)
#### Post date: [May 18, 2021, 10:56am UTC](https://discuss.elastic.co/t/unable-to-calculate-average-bucket-over-multi-layer-data/273270/1 "2021-05-18T10:56:44Z")

</div>

Hi,  
I'm able to calculate average bucket score over one layer of data, but not on two lever hierarchy data.  
Example:

A-parent-group m-group t-team 1  
A-parent-group m-group t-team 4  
A-parent-group n-group p-team 45  
A-parent-group n-group p-team 34  
A-parent-group n-group k-team 3

In above data, the average at group level can be calculated using bucketing at team level and I can get accurate results as  
m-group: 2.5  
n-group: 21.25

Now while I try to calculate average avg at parent group.  
The bucketing at group level will give wrong output as: 29.83  
but actually it should be 11.87

Pls help

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [May 25, 2021, 10:34am UTC](https://discuss.elastic.co/t/unable-to-calculate-average-bucket-over-multi-layer-data/273270/2 "2021-05-25T10:34:25Z")

</div>

Hey,

I think it's more of a use-case thing, what the _correct_ average would look like in this case... I would not have guessed 11.875 🙂

That said, you could go with a [average bucket pipeline aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/search-aggregations-pipeline-avg-bucket-aggregation.html) that actually has a very similar example than your usecase.

Hope that helps!

--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: [June 22, 2021, 10:35am UTC](https://discuss.elastic.co/t/unable-to-calculate-average-bucket-over-multi-layer-data/273270/3 "2021-06-22T10:35:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
