| script-id | String | Stored script or search template ID. Must be unique across the cluster. Required. |
### Query parameters
All parameters are optional.
| Parameter | Data Type | Description |
:--- | :--- | :---
| context | String | Context in which the script or search template is to run. To prevent errors, the API immediately compiles the script or template in this context. |
| cluster_manager_timeout | Time | Amount of time to wait for a connection to the cluster manager. Defaults to 30 seconds. |
| timeout | Time | The period of time to wait for a response. If a response is not received before the timeout value, the request fails and returns an error. Defaults to 30 seconds.|
### Request fields
| Field | Data Type | Description |
:--- | :--- | :---
| script | Object | Defines the script or search template, its parameters, and its language. See *Script object* below. |
*Script object*
| Field | Data Type | Description |
:--- | :--- | :---
| lang | String | Scripting language. Required. |
| source | String or Object | Required. <br/><br/> For scripts, a string with the contents of the script. <br/><br/> For search templates, an object that defines the search template. Supports the same parameters as the [Search API]({{site.url}}{{site.baseurl}}/opensearch/rest-api/search)'s request body. Search templates also support Mustache variables. |
| params | Object | The script's or search template's parameters. |
#### Sample request
The sample uses an index called `books` with the following documents:
"source": "\n int total = 0;\n for (int i = 0; i <doc['\''ratings'\''].length;++i){\n total+=doc['\''ratings'\''][i];\n }\n returntotal;\n "
}
}'
````
See [Execute Painless stored script]({{site.url}}{{site.baseurl}}/opensearch/rest-api/_script-apis/exec-stored-script) for information about running the script.
#### Sample response
The `PUT _scripts/my-first-script` request returns the following field:
````json
{
"acknowledged" : true
}
````
To determine whether the script was successfully created, use the [Get stored script]({{site.url}}{{site.baseurl}}/opensearch/rest-api/_script-apis/get-stored-script/) API, passing the script name as the `script` path parameter.
{: .note}
### Response fields
| Field | Data Type | Description |
:--- | :--- | :---
| acknowledged | Boolean | whether the request was received. |