Script parameters are named values supplied separately from script source. The script reads them through the params object at execution time, keeping changing values such as thresholds outside the business logic. section 5.4.3
Listing 5.29 Dynamically passing a parameter to the script
POST movies/_update/1 { "script": { #1 "source": """ #2 if(ctx._source.boxoffice_gross_in_millions > params.gross_earnings_threshold) {ctx._source.blockbuster = true} else {ctx._source.blockbuster = false} """, "params": { #3 "gross_earnings_threshold":150 } } } #1 Business logic goes here. #2 Checks the value against params #3 Provides the parameter values
A movie update compares box-office earnings with params.gross_earnings_threshold and sets the blockbuster flag. Change the threshold in params without editing the script logic. section 5.4.3
A parameterized script separates:
- Business logic in source. section 5.4.3
- Runtime values in the params object, such as gross_earnings_threshold: 150. section 5.4.3
- Reusable behavior from values that may change, such as raising the threshold to 500. section 5.4.3
