Painless execute API
editPainless execute API
editThe painless execute api is new and the request / response format may change in a breaking way in the future
The Painless execute API allows an arbitrary script to be executed and a result to be returned.
Table 1. Parameters
Name | Required | Default | Description |
---|---|---|---|
|
yes |
- |
The script to execute |
|
no |
|
The context the script should be executed in. |
Contexts
editContexts control how scripts are executed, what variables are available at runtime and what the return type is.
Painless test script context
editThe painless_test
context executes scripts as is and do not add any special parameters.
The only variable that is available is params
, which can be used to access user defined values.
The result of the script is always converted to a string.
If no context is specified then this context is used by default.
Example
editRequest:
POST /_scripts/painless/_execute { "script": { "source": "params.count / params.total", "params": { "count": 100.0, "total": 1000.0 } } }
Response:
{ "result": "0.1" }