Skip to content

Get stored script ​

Introduced 1.0

Retrieves a stored script.

Path parameters ​

ParameterData typeDescription
scriptStringStored script or search template name. Required.

Query parameters ​

ParameterData typeDescription
cluster_manager_timeoutTimeAmount of time to wait for a connection to the cluster manager. Optional, defaults to 30s.

Example request ​

The following retrieves the my-first-script stored script.

json
GET _scripts/my-first-script

Example response ​

The GET _scripts/my-first-script request returns the following fields:

json
{
  "_id" : "my-first-script",
  "found" : true,
  "script" : {
    "lang" : "painless",
    "source" : """
          int total = 0;
          for (int i = 0; i < doc['ratings'].length; ++i) {
            total += doc['ratings'][i];
          }
          return total;
        """
  }
}

Response fields ​

The GET _scripts/my-first-script request returns the following response fields:

FieldData typeDescription
_idStringThe script's name.
foundBooleanThe requested script exists and was retrieved.
scriptObjectThe script definition. See Script object.

Script object ​

FieldData typeDescription
langStringThe script's language.
sourceStringThe script's body.

Released under the Apache License 2.0. Forum · Contact us