# Calculate a new field into new index

**URL:** <https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266>\
**Category:** Kibana\
**Created:** [August 3, 2021, 1:56am UTC](https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266 "2021-08-03T01:56:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shifenglim](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@shifenglim](https://discuss.elastic.co/u/shifenglim)\
**Post date:** [August 3, 2021, 1:56am UTC](https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266/1 "2021-08-03T01:56:46Z")

</div>

I am displaying my data in grafana using elasticseach as a datasource and using a plugin there called metaqueries to help do a calculation on elasticsearch's field like:

A: queryA  
B: queryB  
C: queryC  
D: (A+B) / C

I am able to display the data correctly on a graph, but unfortunately this plugin does not support setting an alert so I am looking for an alternative way.

What I am thinking of is to calculate the fields in elasticsearch from multiple different queries and add that calculated field into a new index, I thought of using a job that runs a program which queries from elasticsearch, calculate the field and add it back into a new index which I will then use in grafana to display in a graph.

Is there any way I can do this calculation in kibana instead?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [August 3, 2021, 3:53pm UTC](https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266/2 "2021-08-03T15:53:49Z")

</div>

Hi @shifenglim ,

welcome to the Kibana community.  
In Kibana there's the Lens editor which, since version 7.14, provides a new feature called "Formula" which enables math on field aggregations: [Lens | Kibana Guide [7.14] | Elastic](https://www.elastic.co/guide/en/kibana/7.14/lens.html#lens-formulas)

Of course this depends on the type of queries you are currently using. Do you have more information about that?

---

<div class="post-metadata">

**Author:** ![shifenglim](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@shifenglim](https://discuss.elastic.co/u/shifenglim)\
**Post date:** [August 4, 2021, 1:51am UTC](https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266/3 "2021-08-04T01:51:24Z")

</div>

Hi Marco, thanks for the reply,  
It looks good however I am unsure if this actually creates the data in a new index to be use somewhere (Grafana) else or is this aggregated view only available in kibana's dashboard.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [August 4, 2021, 8:12am UTC](https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266/4 "2021-08-04T08:12:43Z")

</div>

Formulas will make the computation available only on the Kibana visualization side.

If you want to create new summary index with computation results you can have a look at Transforms: [Transforming data | Elasticsearch Guide [7.14] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html)

---

<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 1, 2021, 8:13am UTC](https://discuss.elastic.co/t/calculate-a-new-field-into-new-index/280266/5 "2021-09-01T08:13:18Z")

</div>

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