2022-09-02 18:09:13 -04:00
|
|
|
---
|
|
|
|
layout: default
|
|
|
|
title: Get Stored Script
|
|
|
|
parent: Script APIs
|
|
|
|
nav_order: 3
|
|
|
|
---
|
|
|
|
|
2023-10-23 10:53:52 -04:00
|
|
|
# Get stored script
|
|
|
|
**Introduced 1.0**
|
|
|
|
{: .label .label-purple }
|
2022-09-02 18:09:13 -04:00
|
|
|
|
|
|
|
Retrieves a stored script.
|
|
|
|
|
2023-10-23 10:53:52 -04:00
|
|
|
## Path parameters
|
2022-09-02 18:09:13 -04:00
|
|
|
|
2022-11-18 15:25:06 -05:00
|
|
|
| Parameter | Data type | Description |
|
2022-09-02 18:09:13 -04:00
|
|
|
:--- | :--- | :---
|
|
|
|
| script | String | Stored script or search template name. Required.|
|
|
|
|
|
2023-10-23 10:53:52 -04:00
|
|
|
## Query parameters
|
2022-09-02 18:09:13 -04:00
|
|
|
|
2022-11-18 15:25:06 -05:00
|
|
|
| Parameter | Data type | Description |
|
2022-09-02 18:09:13 -04:00
|
|
|
:--- | :--- | :---
|
|
|
|
| cluster_manager_timeout | Time | Amount of time to wait for a connection to the cluster manager. Optional, defaults to `30s`. |
|
|
|
|
|
2023-02-20 11:34:20 -05:00
|
|
|
#### Example request
|
2022-09-02 18:09:13 -04:00
|
|
|
|
|
|
|
The following retrieves the `my-first-script` stored script.
|
|
|
|
|
|
|
|
````json
|
|
|
|
GET _scripts/my-first-script
|
|
|
|
````
|
2023-01-30 17:09:38 -05:00
|
|
|
{% include copy-curl.html %}
|
2022-09-02 18:09:13 -04:00
|
|
|
|
2023-02-20 11:34:20 -05:00
|
|
|
#### Example response
|
2022-09-02 18:09:13 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
````
|
|
|
|
|
2023-10-23 10:53:52 -04:00
|
|
|
## Response fields
|
2022-09-02 18:09:13 -04:00
|
|
|
|
|
|
|
The `GET _scripts/my-first-script` request returns the following response fields:
|
|
|
|
|
2022-11-18 15:25:06 -05:00
|
|
|
| Field | Data type | Description |
|
2022-09-02 18:09:13 -04:00
|
|
|
:--- | :--- | :---
|
|
|
|
| _id | String | The script's name. |
|
|
|
|
| found | Boolean | The requested script exists and was retrieved. |
|
|
|
|
| script | Object | The script definition. See [Script object](#script-object). |
|
|
|
|
|
|
|
|
#### Script object
|
|
|
|
|
2022-11-18 15:25:06 -05:00
|
|
|
| Field | Data type | Description |
|
2022-09-02 18:09:13 -04:00
|
|
|
:--- | :--- | :---
|
|
|
|
| lang | String | The script's language. |
|
|
|
|
| source | String | The script's body. |
|