# Math calculation on different fields? How to?

**URL:** <https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269>\
**Category:** Elasticsearch\
**Created:** [May 25, 2018, 7:21am UTC](https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269 "2018-05-25T07:21:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [May 25, 2018, 7:21am UTC](https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269/1 "2018-05-25T07:21:29Z")

</div>

Hi,

our system which we monitor with elastic stack is queuing messages in different parts of the application.

Unfortunately they are stored in different fields. THere are some example field names where the values are stored:

- PerfLogValue
- amqcount

Is it possible to let elasticsearch do some math and sum both fields up?  
I want elasticsearch to calculate PerfLogValue + amqcount.

How can this be done?  
Is there also a way to do so in kibana?

Thanks a lot, Andreas

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 25, 2018, 7:24am UTC](https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269/2 "2018-05-25T07:24:39Z")

</div>

Scripted fields should be able to do this for you, but they can be expensive at scale.

---

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [May 25, 2018, 7:28am UTC](https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269/3 "2018-05-25T07:28:53Z")

</div>

thanks for the fast reply.

scripted fields are always calculated, even if I don't visualize them, right?

Is there another way to run the calculation only when I need them?  
E.g. by requiring the calculation within the query from elasticsearch or from within kibana as json input?

I would like to keep the performance impact as low as possible

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 25, 2018, 8:46am UTC](https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269/4 "2018-05-25T08:46:11Z")

</div>

Not that I am aware of/can recall.

---

<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, 2018, 8:49am UTC](https://discuss.elastic.co/t/math-calculation-on-different-fields-how-to/133269/5 "2018-06-22T08:49:55Z")

</div>

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