# Can 'scripted field' in index patterns be used to calculate a value using two existing fields?

**URL:** <https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778>\
**Category:** Kibana\
**Created:** [September 9, 2021, 12:53pm UTC](https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778 "2021-09-09T12:53:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lchen](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lchen](https://discuss.elastic.co/u/lchen)\
**Post date:** [September 9, 2021, 12:53pm UTC](https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778/1 "2021-09-09T12:53:52Z")

</div>

I have two timestamp fields in my index and I want to calculate the time difference between two fields using scripted fields, and after that, I want to use fields in the visualization. is this possible?

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [September 9, 2021, 2:58pm UTC](https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778/2 "2021-09-09T14:58:27Z")

</div>

Hi @lchen, Welcome 👋

Yes, this is possible: you can use multiple fields from a single document. Please note, that scripted fields are deprecated and runtime fields should be used instead.

You can find some of examples of runtime fields here: [Getting started with runtime fields, Elastic’s implementation of schema on read | Elastic Blog](https://www.elastic.co/blog/getting-started-with-elasticsearch-runtime-fields)

---

<div class="post-metadata">

**Author:** ![lchen](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lchen](https://discuss.elastic.co/u/lchen)\
**Post date:** [September 9, 2021, 3:22pm UTC](https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778/3 "2021-09-09T15:22:10Z")

</div>

i am using an old version so still have script fields instead of run time fields. would this still be possible?

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [September 9, 2021, 3:36pm UTC](https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778/4 "2021-09-09T15:36:59Z")

</div>

Yes, here you can find some examples: [Using Painless in Kibana scripted fields | Elastic Blog](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)

I think you'd need something similar to `Combine two string values` example.

---

<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:** [October 7, 2021, 3:37pm UTC](https://discuss.elastic.co/t/can-scripted-field-in-index-patterns-be-used-to-calculate-a-value-using-two-existing-fields/283778/5 "2021-10-07T15:37:00Z")

</div>

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