# Painless Script - Access Interval Variable

**URL:** https://discuss.elastic.co/t/painless-script-access-interval-variable/268000
**Category:** Kibana
**Tags:** painless
**Created:** [March 22, 2021, 5:24pm UTC](https://discuss.elastic.co/t/painless-script-access-interval-variable/268000 "2021-03-22T17:24:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lamp123432](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lamp123432](https://discuss.elastic.co/u/lamp123432)
#### Post date: [March 22, 2021, 5:24pm UTC](https://discuss.elastic.co/t/painless-script-access-interval-variable/268000/1 "2021-03-22T17:24:25Z")

</div>

Using Scripted Fields, I'm trying to do some math and I need to divide the current `interval` / 1000.

Interval is dynamic as we zoom in and out of graphs, could be per minute, per 5 minutes, for hour, etc.

In TSVB, Bucket Scripts allows to access the internal with the following param: `params._interval`

How to do it in scripted fields?

---

<div class="post-metadata">

### Author: ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)
#### Post date: [March 23, 2021, 12:19am UTC](https://discuss.elastic.co/t/painless-script-access-interval-variable/268000/2 "2021-03-23T00:19:22Z")

</div>

AFAIK

> Scripted fields compute data on the fly from the data in your Elasticsearch indices. The data is shown on the Discover tab as part of the document data, and you can use scripted fields in your visualizations.

So if the field is not in the index, you cannot access it.

> **[Index patterns has been renamed to data views. | Kibana Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/kibana/current/managing-index-patterns.html#scripted-fields)**

---

<div class="post-metadata">

### Author: ![lamp123432](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lamp123432](https://discuss.elastic.co/u/lamp123432)
#### Post date: [March 23, 2021, 3:15pm UTC](https://discuss.elastic.co/t/painless-script-access-interval-variable/268000/3 "2021-03-23T15:15:05Z")

</div>

Pretty sure there are special variables you can call, such as the interval variable... We can do it in TSVB, maybe someone from Elastic needs to confirm.

Here's my current code for the scripted field:

`if (doc['ifHCInOctets'].size() != 0) { doc['ifHCInOctets'].value * 8 / 60 }`

This part of my code: `8 / 60 }` needs to be `8 / $interval }` just like in TSVB with `params._interval`

---

<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: [April 20, 2021, 3:15pm UTC](https://discuss.elastic.co/t/painless-script-access-interval-variable/268000/4 "2021-04-20T15:15:25Z")

</div>

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