# Calculating a scripted field

**URL:** <https://discuss.elastic.co/t/calculating-a-scripted-field/143039>\
**Category:** Kibana\
**Created:** [August 5, 2018, 1:53am UTC](https://discuss.elastic.co/t/calculating-a-scripted-field/143039 "2018-08-05T01:53:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Fathi\_Yassien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmed_fathi_yassien/32/34110_2.png) [@Ahmed\_Fathi\_Yassien](https://discuss.elastic.co/u/Ahmed_Fathi_Yassien)\
**Post date:** [August 5, 2018, 1:53am UTC](https://discuss.elastic.co/t/calculating-a-scripted-field/143039/1 "2018-08-05T01:53:32Z")

</div>

Hi,

I have 2 timestamps for 2 different actions, one representing the sent action for the SMS and the other representing the delivery action with identical Id for both actions (respresenting processing the same SMS).

The question is: Could anyone help on how to calculate the time difference in seconds between the 2 actions per each identical Id and showing it inline with the "Receive DLR" record.

 ![sample](https://us1.discourse-cdn.com/elastic/original/3X/e/6/e6bd1dfcbe7d93a460ec0a91bb065abecdeddf98.png)

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [August 6, 2018, 3:25pm UTC](https://discuss.elastic.co/t/calculating-a-scripted-field/143039/2 "2018-08-06T15:25:16Z")

</div>

Scripted fields are for calculating fields within a single document. Sounds like you are storing the two event times in 2 documents. If you change the way you are storing data in Elasticsearch to have the two times be stored in a single ES document, then you could create a scripted field that would calculate the difference.

---

<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 3, 2018, 3:25pm UTC](https://discuss.elastic.co/t/calculating-a-scripted-field/143039/3 "2018-09-03T15:25:16Z")

</div>

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