# Use aggregation in scripted fields

**URL:** <https://discuss.elastic.co/t/use-aggregation-in-scripted-fields/23911>\
**Category:** Kibana\
**Created:** [June 18, 2015, 12:53pm UTC](https://discuss.elastic.co/t/use-aggregation-in-scripted-fields/23911 "2015-06-18T12:53:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quili](https://avatars.discourse-cdn.com/v4/letter/q/3d9bf3/32.png) [@Quili](https://discuss.elastic.co/u/Quili)\
**Post date:** [June 18, 2015, 12:53pm UTC](https://discuss.elastic.co/t/use-aggregation-in-scripted-fields/23911/1 "2015-06-18T12:53:45Z")

</div>

Hi Guys,  
I'm really new to Elasticsearch and Kibana.  
At the moment I try to normalize a number field of a document. Therefore I want to use this formula within a scripted field:  
normalized\_field=(field-min)/(max-min).

So I need to compute min and max aggregation in the script, before compute the formula. Is it possible to store the aggregation result as variable and calculate the formula within the same script?  
If yes, then how?

Thanks for your help! 🙂

---

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [June 18, 2015, 1:48pm UTC](https://discuss.elastic.co/t/use-aggregation-in-scripted-fields/23911/2 "2015-06-18T13:48:33Z")

</div>

Unfortunately, that won't be possible until Elasticsearch 2.0 introduces arithmetic functions on top of pipeline aggregation that. This is ES issue [#9876](https://github.com/elastic/elasticsearch/issues/9876), already in ES master, so documentation is available here:  
[https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-pipeline-series-arithmetic-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-pipeline-series-arithmetic-aggregation.html)

We are still working on a timeline of when that will be integrated into Kibana, so feel free to add an enhancement request here with your use case! [https://github.com/elastic/kibana](https://github.com/elastic/kibana)

---

<div class="post-metadata">

**Author:** ![Quili](https://avatars.discourse-cdn.com/v4/letter/q/3d9bf3/32.png) [@Quili](https://discuss.elastic.co/u/Quili)\
**Post date:** [June 19, 2015, 5:19am UTC](https://discuss.elastic.co/t/use-aggregation-in-scripted-fields/23911/3 "2015-06-19T05:19:26Z")

</div>

This sounds very interesting. I'll trace the progress!  
Thanks for your advise.

---

<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, 2:17pm UTC](https://discuss.elastic.co/t/use-aggregation-in-scripted-fields/23911/4 "2017-07-06T14:17:50Z")

</div>


