[[painless-contexts]]
== Painless contexts

A Painless script is evaluated within a context. Each context has values that
are available as local variables, a whitelist that controls the available
classes, and the methods and fields within those classes (API), and
if and what type of value is returned.

A Painless script is typically executed within one of the contexts in the table
below. Note this is not necessarily a comprehensive list as custom plugins and
specialized code may define new ways to use a Painless script.

[options="header",cols="<1,<1,<1"]
|====
| Name                              | Painless Documentation
                                    | Elasticsearch Documentation
| Ingest processor                  | <<painless-ingest-processor-context, Painless Documentation>>
                                    | {ref}/script-processor.html[Elasticsearch Documentation]
| Update                            | <<painless-update-context, Painless Documentation>>
                                    | {ref}/docs-update.html[Elasticsearch Documentation]
| Update by query                   | <<painless-update-by-query-context, Painless Documentation>>
                                    | {ref}/docs-update-by-query.html[Elasticsearch Documentation]
| Reindex                           | <<painless-reindex-context, Painless Documentation>>
                                    | {ref}/docs-reindex.html[Elasticsearch Documentation]
| Sort                              | <<painless-sort-context, Painless Documentation>>
                                    | {ref}/search-request-sort.html[Elasticsearch Documentation]
| Similarity                        | <<painless-similarity-context, Painless Documentation>>
                                    | {ref}/index-modules-similarity.html[Elasticsearch Documentation]
| Weight                            | <<painless-weight-context, Painless Documentation>>
                                    | {ref}/index-modules-similarity.html[Elasticsearch Documentation]
| Score                             | <<painless-score-context, Painless Documentation>>
                                    | {ref}/query-dsl-function-score-query.html[Elasticsearch Documentation]
| Field                             | <<painless-field-context, Painless Documentation>>
                                    | {ref}/search-request-script-fields.html[Elasticsearch Documentation]
| Filter                            | <<painless-filter-context, Painless Documentation>>
                                    | {ref}/query-dsl-script-query.html[Elasticsearch Documentation]
| Minimum should match              | <<painless-min-should-match-context, Painless Documentation>>
                                    | {ref}/query-dsl-terms-set-query.html[Elasticsearch Documentation]
| Metric aggregation initialization | <<painless-metric-agg-init-context, Painless Documentation>>
                                    | {ref}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Metric aggregation map            | <<painless-metric-agg-map-context, Painless Documentation>>
                                    | {ref}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Metric aggregation combine        | <<painless-metric-agg-combine-context, Painless Documentation>>
                                    | {ref}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Metric aggregation reduce         | <<painless-metric-agg-reduce-context, Painless Documentation>>
                                    | {ref}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Bucket script aggregation         | <<painless-bucket-script-agg-context, Painless Documentation>>
                                    | {ref}/search-aggregations-pipeline-bucket-script-aggregation.html[Elasticsearch Documentation]
| Bucket selector aggregation       | <<painless-bucket-selector-agg-context, Painless Documentation>>
                                    | {ref}/search-aggregations-pipeline-bucket-selector-aggregation.html[Elasticsearch Documentation]
| Watcher condition                 | <<painless-watcher-condition-context, Painless Documentation>>
                                    | {xpack-ref}/condition-script.html[Elasticsearch Documentation]
| Watcher transform                 | <<painless-watcher-transform-context, Painless Documentation>>
                                    | {xpack-ref}/transform-script.html[Elasticsearch Documentation]
|====

include::painless-contexts/painless-context-examples.asciidoc[]

include::painless-contexts/index.asciidoc[]
