# 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:** 1\
**Showing post:** 2

<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`.

---

_[View the full topic](https://discuss.elastic.co/t/scripted-fields-vs-runtime-fields/263962)._
