# Custom aggregation - mean of squared values in a time bucket

**URL:** <https://discuss.elastic.co/t/custom-aggregation-mean-of-squared-values-in-a-time-bucket/178273>\
**Category:** Elasticsearch\
**Created:** [April 24, 2019, 2:20pm UTC](https://discuss.elastic.co/t/custom-aggregation-mean-of-squared-values-in-a-time-bucket/178273 "2019-04-24T14:20:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roland\_Groza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roland_groza/32/44733_2.png) [@Roland\_Groza](https://discuss.elastic.co/u/Roland_Groza)\
**Post date:** [April 24, 2019, 2:20pm UTC](https://discuss.elastic.co/t/custom-aggregation-mean-of-squared-values-in-a-time-bucket/178273/1 "2019-04-24T14:20:37Z")

</div>

Hi,

I'm trying to create a custom aggregation for buckets of time (I'm also using the date histogram) on a certain field following the formula:

```
log(mean(I.^2)/mean(I)^2)

```

Where `I` is all the values in the bucket of time.

I'm having a hard time calculating the mean of squared of values (`mean(I.^2)`). `mean(I)^2` is easy to do using the avg. aggregate ES provides already.

Is there any way I could achieve this without doing the aggregation myself?

---

<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:** [May 22, 2019, 2:20pm UTC](https://discuss.elastic.co/t/custom-aggregation-mean-of-squared-values-in-a-time-bucket/178273/2 "2019-05-22T14:20:39Z")

</div>

Closed on May 22, 2019, 2:20pm UTC

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