# Scripted fields vs runtime fields

**URL:** <https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962>\
**Category:** Elasticsearch\
**Created:** [February 11, 2021, 7:58am UTC](https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962 "2021-02-11T07:58:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaoranlaos](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Shaoranlaos](https://discuss.elastic.co/u/Shaoranlaos)\
**Post date:** [February 11, 2021, 7:58am UTC](https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962/1 "2021-02-11T07:58:29Z")

</div>

Hello,

i have read the introduction of runtime fields under

> **[Introducing Elasticsearch runtime fields](https://www.elastic.co/de/blog/introducing-elasticsearch-runtime-fields)**
>
> In 7.11, we’re excited to announce schema on read in the Elastic Stack. We now offer the best of both worlds on a single platform. Schema on read for performance and schema on write for flexibility. We call our implementation runtime fields.

And i'm wondering where the differences to the "old" scripted fields are beside the ability define them in a mapping and not only in a query?

Is it simply a more performant variant or will the scripted fields still exist because they serve a case i'm not seeing?

Are they even the same thing (because they are not mentioned in the blog post)? For me they appeare pretty similar.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [February 11, 2021, 10:57pm UTC](https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962/2 "2021-02-11T22:57:45Z")

</div>

The traditional `script_fields` can be used only on the last stage of a search request – fetch phase, which happens after we have already selected top N hits based on some query, and would like to decorate those hits with some extra information by adding extra script fields to those hits.

Runtime fields are much more powerful. Unlike traditional `script_fields`, you can use them in the query phase of a search request to select docs based on them or use their values in aggs. For example, you can define a new runtime field, and [write a query that will select documents based on this new defined field](https://www.elastic.co/guide/en/elasticsearch/reference/master/runtime-examples.html#runtime-examples-runtime-field).  
Another example, you can define a new runtime field, and run an aggregation based on it.  
These examples are something you can't do with a traditional `script_fields`.

---

<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 11, 2021, 10:58pm UTC](https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962/3 "2021-03-11T22:58:34Z")

</div>

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