Scripted fields vs runtime fields

Hello,

i have read the introduction of runtime fields under

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.

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

3 Likes