# Scripted fields for calculation

**URL:** <https://discuss.elastic.co/t/scripted-fields-for-calculation/67963>\
**Category:** Elasticsearch\
**Created:** [December 4, 2016, 11:11pm UTC](https://discuss.elastic.co/t/scripted-fields-for-calculation/67963 "2016-12-04T23:11:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TWalter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twalter/32/41239_2.png) [@TWalter](https://discuss.elastic.co/u/TWalter)\
**Post date:** [December 4, 2016, 11:11pm UTC](https://discuss.elastic.co/t/scripted-fields-for-calculation/67963/1 "2016-12-04T23:11:43Z")

</div>

Hello there,

i have a Problem with an Analysis. I want to calculate the Availability of Machines over the selected timerange in Kibana.

The Problam is:

- The two variables i need are sum of the variables of the several datasets.
- The two variables i need have the same name, but in different types of the Index

Does somebody know a solution, where i can dynamically calculate the Availability?

Is there a solution with scripted fields?

Thanks to all.

---

<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:** [December 5, 2016, 9:20am UTC](https://discuss.elastic.co/t/scripted-fields-for-calculation/67963/2 "2016-12-05T09:20:14Z")

</div>

Hey,

so is this an issue of writing a useful aggregation first? If so, it might make sense to share two documents/mapping/indices as a minimal example, so folks can take a look if it is possible to join the data the way you want.

---Alex

---

<div class="post-metadata">

**Author:** ![TWalter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twalter/32/41239_2.png) [@TWalter](https://discuss.elastic.co/u/TWalter)\
**Post date:** [December 13, 2016, 8:35am UTC](https://discuss.elastic.co/t/scripted-fields-for-calculation/67963/3 "2016-12-13T08:35:58Z")

</div>

Hey,

ok, i have two types of documents.

Doc 1 (Stops):  
{  
type: "Stops"  
duration: x  
]

Doc 2 (Shifts)  
{  
type:"Shifts"  
duration y  
}

and now i do a metric aggregation over a period of time, where i calculate the sum of duration of the Stops and the sum of duration of the Shifts (two types). In Kibana i show it on metric visualizations. Now i want to calculate (sum of duration stops - sum of duration shifts) / (sum of duration shifts). I need to do it dynamically in Kibana. Is there any possibility to implement it there?

---

<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:** [January 10, 2017, 8:36am UTC](https://discuss.elastic.co/t/scripted-fields-for-calculation/67963/4 "2017-01-10T08:36:04Z")

</div>

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