[[create-stored-script-api]] === Create or update stored script API ++++ Create or update stored script ++++ Creates or updates a <> or <>. [source,console] ---- PUT _scripts/my-stored-script { "script": { "lang": "painless", "source": "Math.log(_score * 2) + params['my_modifier']" } } ---- //// [source,console] ---- DELETE _scripts/my-stored-script ---- // TEST[continued] //// [[create-stored-script-api-request]] ==== {api-request-title} `PUT _scripts/` `POST _scripts/` `PUT _scripts//` `POST _scripts//` [[create-stored-script-api-prereqs]] ==== {api-prereq-title} * If the {es} {security-features} are enabled, you must have the `manage` <> to use this API. [[create-stored-script-api-path-params]] ==== {api-path-parms-title} ``:: (Required, string) Identifier for the stored script or search template. Must be unique within the cluster. ``:: (Optional, string) Context in which the script or search template should run. To prevent errors, the API immediately compiles the script or template in this context. [[create-stored-script-api-query-params]] ==== {api-query-parms-title} `context`:: (Optional, string) Context in which the script or search template should run. To prevent errors, the API immediately compiles the script or template in this context. + If you specify both this and the `` request path parameter, the API uses the request path parameter. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms] [role="child_attributes"] [[create-stored-script-api-request-body]] ==== {api-request-body-title} `script`:: (Required, object) Contains the script or search template, its parameters, and its language. + .Properties of `script` [%collapsible%open] ==== `lang`:: (Required, string) <>. For search templates, use `mustache`. `source`:: (Required, string or object) For scripts, a string containing the script. + For search templates, an object containing the search template. The object supports the same parameters as the <>'s request body. Also supports https://mustache.github.io/[Mustache] variables. See <>. `params`:: (Optional, object) Parameters for the script or search template. ====