| 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.|
| 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]({{site.url}}{{site.baseurl}}/api-reference/search) API request body. Search templates also support Mustache variables. |
See [Execute Painless stored script]({{site.url}}{{site.baseurl}}/api-reference/script-apis/exec-stored-script/) for information about running the script.
To determine whether the script was successfully created, use the [Get stored script]({{site.url}}{{site.baseurl}}/api-reference/script-apis/get-stored-script/) API, passing the script name as the `script` path parameter.
The following request creates the Painless script `multiplier-script`. The request sums the ratings for each book, multiplies the summed value by the `multiplier` parameter, and displays the result in the output:
````json
PUT _scripts/multiplier-script
{
"script": {
"lang": "painless",
"source": """
int total = 0;
for (int i = 0; i <doc['ratings'].length;++i){
total += doc['ratings'][i];
}
return total * params['multiplier'];
"""
}
}
````
{% include copy-curl.html %}
### Example response
The `PUT _scripts/multiplier-script` request returns the following field: