# Running custom aggregations in ES

**URL:** <https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213>\
**Category:** Elasticsearch\
**Created:** [July 30, 2020, 11:59am UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213 "2020-07-30T11:59:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yBother](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yBother](https://discuss.elastic.co/u/yBother)\
**Post date:** [July 30, 2020, 11:59am UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/1 "2020-07-30T11:59:15Z")

</div>

Is it possible to run custom "aggregations" directly db side?  
I know there are builtin functionalities like averaging etc.  
But I want to run a custom function on the data that is stored in a specific index.

---

<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:** [August 3, 2020, 10:43am UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/2 "2020-08-03T10:43:57Z")

</div>

Can you be more specific and explain your problem in more detail?

You could always write your own aggregation implementation if you wanted, but maybe your issue can be solved in an easier way. Also you may want to take a look at differnet aggregations who have scripting support and might help you to become more dynamic.

---

<div class="post-metadata">

**Author:** ![Raster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raster/32/47522_2.png) [@Raster](https://discuss.elastic.co/u/Raster)\
**Post date:** [August 7, 2020, 10:11am UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/3 "2020-08-07T10:11:37Z")

</div>

Hi Alexander,

I am intersted in knowing custom aggregation implementation steps.  
Can you please elaborate.  
Thanks.  
R

---

<div class="post-metadata">

**Author:** ![yBother](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yBother](https://discuss.elastic.co/u/yBother)\
**Post date:** [August 11, 2020, 1:37pm UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/4 "2020-08-11T13:37:02Z")

</div>

Well let's say I have multiple parameter values (id: string, timestamp: date, value:number) per index and I want to calculate something out of that directly on db side, ideally supporting any parameters.

---

<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:** [August 12, 2020, 8:21am UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/5 "2020-08-12T08:21:57Z")

</div>

have you seen the `script` support in many aggregations? See [https://www.elastic.co/guide/en/elasticsearch/reference/7.8/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script) as an example for the terms agg (same applies for histogram as well).

---

<div class="post-metadata">

**Author:** ![yBother](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yBother](https://discuss.elastic.co/u/yBother)\
**Post date:** [August 24, 2020, 5:31pm UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/6 "2020-08-24T17:31:36Z")

</div>

okay thats useful.  
_The `terms` aggregation does not support collecting terms from multiple fields in the same document._

Where can I look up all possibilities I have using scripts?  
Is it even possible to perform calculations that need fields from other documents in the same index?

---

<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:** [September 21, 2020, 5:31pm UTC](https://discuss.elastic.co/t/running-custom-aggregations-in-es/243213/7 "2020-09-21T17:31:42Z")

</div>

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