Create or update a script or search template

Auth

Creates or updates a stored script or search template.

More about searching templates

Required authorization

Cluster privileges manage

Path parameters

id string required

The identifier for the stored script or search template. It must be unique within the cluster.

context string optional

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

context string

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_timeout string · 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 -1 to indicate that the request should never timeout.

timeout string · 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 -1 to indicate that the request should never timeout.

Request body

script object required

The script or search template, its parameters, and its language.

lang union anyOf required

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: painless expression mustache java
options map string to string
source union oneOf required

The script source. For search templates, an object containing the search template.

One of:

Response

application/json
acknowledged boolean required

For a successful response, this value is always true. On failure, an exception is returned instead.