Create or update a script or search template
- POST also PUT /_scripts/{id}/{context}
- POST also PUT /_scripts/{id}
Creates or updates a stored script or search template.
- Cluster privileges:
manage
Path Parameters
-
idstring Idrequired -
The identifier for the stored script or search template. It must be unique within the cluster.
-
contextstring Nameoptional -
The context in which the script or search template should run. To prevent errors, the API immediately compiles the script or template in this context.
Leave it out to use
/_scripts/{id}.
Query Parameters
-
contextstring Name The 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
<context>path parameter, the API uses the request path parameter.-
master_timeoutstring Duration · default: 30s The period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. It can also be set to
-1to indicate that the request should never timeout.-
timeoutstring Duration · default: 30s The period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. It can also be set to
-1to indicate that the request should never timeout.
Request
-
scriptStoredScriptrequired -
The script or search template, its parameters, and its language.
-
langScriptLanguagerequired -
The language the script is written in. For search templates, use
mustache.Supported values include:
painless: Painless scripting language, purpose-built for Elasticsearch.expression: Lucene’s expressions language, compiles a JavaScript expression to bytecode.mustache: Mustache templated, used for templates.java: Expert Java API
-
Values:
painlessexpressionmustachejava -
optionsmap string to string -
sourceScriptSourcerequired -
The script source. For search templates, an object containing the search template.
Response
-
acknowledgedbooleanrequired -
For a successful response, this value is always true. On failure, an exception is returned instead.