<commit_before>[[painless-execute-api]]
=== Painless execute API

experimental[The 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.

[[painless-execute-api-parameters]]
.Parameters
[options="header"]
|======
| Name             | Required  | Default                | Description
| `script`         | yes       | -                      | The script to execute
| `context`        | no        | `execute_api_script`   | The context the script should be executed in.
|======

==== Contexts

Contexts control how scripts are executed, what variables are available at runtime and what the return type is.

===== Painless test script context

The `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

Request:

[source,js]
----------------------------------------------------------------
POST /_scripts/painless/_execute
{
  "script": {
    "source": "params.count / params.total",
    "params": {
      "count": 100.0,
      "total": 1000.0
    }
  }
}
----------------------------------------------------------------
// CONSOLE<commit_msg>[DOCS] fixed incorrect default<commit_after>[[painless-execute-api]]
=== Painless execute API

experimental[The 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.

[[painless-execute-api-parameters]]
.Parameters
[options="header"]
|======
| Name             | Required  | Default                | Description
| `script`         | yes       | -                      | The script to execute
| `context`        | no        | `painless_test`        | The context the script should be executed in.
|======

==== Contexts

Contexts control how scripts are executed, what variables are available at runtime and what the return type is.

===== Painless test script context

The `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

Request:

[source,js]
----------------------------------------------------------------
POST /_scripts/painless/_execute
{
  "script": {
    "source": "params.count / params.total",
    "params": {
      "count": 100.0,
      "total": 1000.0
    }
  }
}
----------------------------------------------------------------
// CONSOLE
{'fraction_non_alphanumeric': 0.1742398360095661, 'fraction_numerical': 0.0061496412709258624, 'mean_word_length': 2.179153094462541, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1207089', 'n_tokens_mistral': 737, 'n_tokens_neox': 698, 'n_words': 316}