# How to do Calculation in Elasticsearch Query

**URL:** <https://discuss.elastic.co/t/how-to-do-calculation-in-elasticsearch-query/323496>\
**Category:** Elasticsearch\
**Created:** [January 19, 2023, 10:25am UTC](https://discuss.elastic.co/t/how-to-do-calculation-in-elasticsearch-query/323496 "2023-01-19T10:25:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [January 19, 2023, 2:43pm UTC](https://discuss.elastic.co/t/how-to-do-calculation-in-elasticsearch-query/323496/2 "2023-01-19T14:43:47Z")

</div>

You know Uptime/ Heartbeat does all that for you...cert check and alert.

But yes you can create a runtime field to calculate the difference assuming you are on a fairly recent version.

I had a post on that let me look

Perhaps this will help

> [@Calculate elapsed time in Kibana?](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575/2):
>
> Hi @TXBigDawg1836 Welcome to the community Yup add a runtime field to the Data View here is the code long datenow = new Date().getTime(); long datewas = doc['@timestamp'].value.getMillis(); emit (datenow - datewas); Create / Set the Field Chose your format.... In Discover Now Table...

---

_[View the full topic](https://discuss.elastic.co/t/how-to-do-calculation-in-elasticsearch-query/323496)._
