# Switch from scripted fields to runtime fields?

**URL:** <https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295>\
**Category:** Kibana\
**Tags:** runtime-fields\
**Created:** [February 25, 2022, 3:15pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295 "2022-02-25T15:15:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![glushkov](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@glushkov](https://discuss.elastic.co/u/glushkov)\
**Post date:** [February 25, 2022, 3:15pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/1 "2022-02-25T15:15:51Z")

</div>

Hi,  
Kibana is warning me since ever when I look at Management \> Index patterns \> \<index\_pattern\_name\> \> Scripted fields that "Scripted fields" are deprecated and one should use "runtime fields" instead. To be prepared, with the new patterns which I create I wanted to create "runtime fields" instead of "scripted fields" but it looks like getting the same functionality is not really possible, right? There is no way / place in Kibana to create a "runtime field" which would create on top of an existing index which I can use later in my Kibana dashboards. One can define "runtime field" when creating a new "Index Template", but that's not the same, isn't it?

Or let me put it the other way around, there is no way currently for a person who is authorized to create an "Index Pattern" but is not authorized to create indexies to implement a formula in a "runtime field" as one can with "scripted field", is that correct?

---

<div class="post-metadata">

**Author:** ![Dzmitry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dzmitry/32/65026_2.png) [@Dzmitry](https://discuss.elastic.co/u/Dzmitry)\
**Post date:** [February 25, 2022, 3:46pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/2 "2022-02-25T15:46:18Z")

</div>

Hi @glushkov ,

FIrst of all, there is no automated method of converting scripted fields into runtime fields, just in case you thought about it.

You can find a good & short explanation on key differences scripted vs runtime [here](https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962/2) and it will probably give you understanding about the difference in terms of user permissions.

So in short, user need to have [indices privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html#privileges-list-indices) to set/update mappings and runtime field as part of it.

There is also a good [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html) on runtime fields.

Regards, Dzmitry

---

<div class="post-metadata">

**Author:** ![glushkov](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@glushkov](https://discuss.elastic.co/u/glushkov)\
**Post date:** [February 25, 2022, 4:05pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/3 "2022-02-25T16:05:24Z")

</div>

Thanks for the fast reply @Dzmitry ,

but that does not answer my question. I have read a lot on the last several hours on the topic of the differences between the two. I understand that there are two ways to create runtime fields.

- One is in [index mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-mapping-fields.html) - in this case the field is defined at index creation time. Obviously, this one is not accessible to me.
- The second one is in the [search request time](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html). This looks like something which might have been available in the Kibana interface - is it?

If not, then I do not see how runtime fields can replace the current functionality of scripted fields. I understand that one saves disk space with them and CPU load on indexing time but so do "scripted\_fields"..

The bottom line is that I don't see how the advantage of "users should not bother administrators for new variables" advertised [here](https://www.elastic.co/es/elasticon/archive/2020/global/schema-on-read-with-runtime-fields) can be used / taken advantage of if the user uses Kibana only. If I write my GET statements, it is clear of course..

Cheers,  
Ivan

---

<div class="post-metadata">

**Author:** ![Dzmitry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dzmitry/32/65026_2.png) [@Dzmitry](https://discuss.elastic.co/u/Dzmitry)\
**Post date:** [February 26, 2022, 2:08pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/4 "2022-02-26T14:08:41Z")

</div>

@glushkov,

There is UI to create runtime field indeed. While on Discover click 3 dots button right to index pattern selection and select `Add field to Index Pattern`. You should see the following form:

 ![Screenshot 2022-02-25 at 19.13.26](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5c778beb0bc1e85ac6d20c34add311721cf1b373.png)

But you still might face the permission issue. There is no a dedicated role for adding Runtime Fields at the moment, but it might be [added](https://github.com/elastic/elasticsearch/issues/48856#issuecomment-827546337) in future stack releases.

The reason behind having required permission for Runtime Fields functionality is related to avoid potential search performance degradation, caused by non-optimal modification of the index mapping.

Regards, Dzmitry

---

<div class="post-metadata">

**Author:** ![glushkov](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@glushkov](https://discuss.elastic.co/u/glushkov)\
**Post date:** [February 26, 2022, 3:52pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/5 "2022-02-26T15:52:25Z")

</div>

Perfect!  
That is exactly what I was looking for.  
Thanks,  
Ivan

---

<div class="post-metadata">

**Author:** ![glushkov](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@glushkov](https://discuss.elastic.co/u/glushkov)\
**Post date:** [February 28, 2022, 9:57am UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/6 "2022-02-28T09:57:49Z")

</div>

Hi @Dzmitry ,  
where do I find the runtime field afterwards and edit it? Currently, the one I have defined is wrong and I cannot see my index at all - all shards are failing with:

```auto
org.elasticsearch.index.fielddata.ScriptDocValues$Dates.get(ScriptDocValues.java:150)
org.elasticsearch.index.fielddata.ScriptDocValues$Dates.getValue(ScriptDocValues.java:144)
emit((doc['endtime'].value.millis-doc['starttime'].value.millis)/3600000)
                                                  ^---- HERE

```

Cheers,  
Ivan

---

<div class="post-metadata">

**Author:** ![majagrubic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/majagrubic/32/74459_2.png) [@majagrubic](https://discuss.elastic.co/u/majagrubic)\
**Post date:** [February 28, 2022, 11:51am UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/7 "2022-02-28T11:51:57Z")

</div>

In Discover, if you click on a field in the field sidebar, you'll see a small "Edit" icon. Clicking it will open field details, including the script you defined and you'll be able to edit it from there.

 ![Screenshot 2022-02-28 at 12.50.58](https://us1.discourse-cdn.com/elastic/original/3X/9/1/91119a492fdea1bd817e633d05640240daaa132d.png)

---

<div class="post-metadata">

**Author:** ![glushkov](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@glushkov](https://discuss.elastic.co/u/glushkov)\
**Post date:** [February 28, 2022, 1:22pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/8 "2022-02-28T13:22:40Z")

</div>

Nice! Thanks!

---

<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:** [March 28, 2022, 1:23pm UTC](https://discuss.elastic.co/t/switch-from-scripted-fields-to-runtime-fields/298295/9 "2022-03-28T13:23:05Z")

</div>

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