Get stored script

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.

  1. GET _scripts/my-first-script

copy

Example response

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

  1. {
  2. "_id" : "my-first-script",
  3. "found" : true,
  4. "script" : {
  5. "lang" : "painless",
  6. "source" : """
  7. int total = 0;
  8. for (int i = 0; i < doc['ratings'].length; ++i) {
  9. total += doc['ratings'][i];
  10. }
  11. return total;
  12. """
  13. }
  14. }

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.

Get Stored Script - 图1