liveBook · Manning

Scripted update

As explained in Elasticsearch in Action, Second Edition

A scripted update is a document modification whose changes are computed by an executable script and may depend on conditions.

A scripted update modifies an existing Elasticsearch document with executable logic. Instead of supplying only fixed field values, the request places a script under _update; the script reads and changes fields through ctx._source. Conditions can decide whether and how the document changes. section 5.4.3

Classifying a movie as a blockbuster

A movie can receive a blockbuster flag when its box-office earnings exceed a threshold. The script can compare ctx._source.boxoffice_gross_in_millions with a fixed value, or receive the threshold dynamically through params. This keeps the update logic in source while allowing the business value to change.

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains script objects, ctx._source, array methods, field assignments, if/else logic, and parameters through focused REST examples.
Examples
Demonstrates movie actors, ratings, runtime, box-office earnings, blockbuster flags, and dynamic gross-earnings thresholds.
What it assumes
Assumes familiarity with updating existing documents and introduces script source, ctx._source, array methods, and parameters.
What you can do after
Apply it via the _update endpoint to add, remove, or conditionally change fields in an existing document.
How it connects
Connects scripted updates to the update API, document source fields, arrays, conditional logic, and script parameters.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.