Painless is Elasticsearch’s default scripting language for scripted document updates. Use it to change fields, edit lists, or apply conditional business logic. section 5.4.3
A script contains three main parts:
- source — the update logic, such as modifying ctx._source. section 5.4.3
- lang — the scripting language; Painless is the default, with other supported language options listed. section 5.4.3
- params — values supplied separately from the logic, such as a configurable earnings threshold. section 5.4.3
Conditionally flag a blockbuster
POST movies/_update/1 { "script": { "source": "if (ctx._source.boxoffice_gross_in_millions > params.gross_earnings_threshold) { ctx._source.blockbuster = true } else { ctx._source.blockbuster = false }", "params": { "gross_earnings_threshold": 150 } } } The script reads the document through ctx._source and keeps the threshold outside the logic, so the value can change without rewriting the condition.
