---
title: Painless contexts
description: A Painless script is evaluated within a context. Each context has values that are available as local variables, an allowlist that controls the available...
url: https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-contexts
products:
  - Painless
---

# Painless contexts
A Painless script is evaluated within a context. Each context has values that are available as local variables, an allowlist that controls the available classes, and the methods and fields within those classes (API), and if and what type of value is returned.
Painless scripts typically run within one of the contexts in the following table. Before using a Painless context, [configure the example data](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-context-examples). Each context example is configured to operate on this data.

| Name                              | Painless Documentation                                                                                                                                      | Elasticsearch Documentation                                                                                                                                          |
|-----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Runtime field                     | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-runtime-fields-context)      | [Elasticsearch Documentation](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/2395/manage-data/data-store/mapping/runtime-fields)                      |
| Ingest processor                  | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-ingest-processor-context)    | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/enrich-processor/script-processor)                                     |
| Update                            | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-update-context)              | [Elasticsearch Documentation](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update)                                                          |
| Update by query                   | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-update-by-query-context)     | [Elasticsearch Documentation](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update-by-query)                                                 |
| Reindex                           | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-reindex-context)             | [Elasticsearch Documentation](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-reindex)                                                         |
| Sort                              | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-sort-context)                | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/elasticsearch/rest-apis/sort-search-results)                           |
| Similarity                        | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-similarity-context)          | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/elasticsearch/index-settings/similarity)                               |
| Weight                            | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-weight-context)              | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/elasticsearch/index-settings/similarity)                               |
| Score                             | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-score-context)               | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/query-languages/query-dsl/query-dsl-function-score-query)              |
| Field                             | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-field-context)               | [Elasticsearch Documentation](/elastic/docs-builder/docs/2395/reference/elasticsearch/rest-apis/retrieve-selected-fields#script-fields)                              |
| Filter                            | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-filter-context)              | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/query-languages/query-dsl/query-dsl-script-query)                      |
| Minimum should match              | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-min-should-match-context)    | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/query-languages/query-dsl/query-dsl-terms-set-query)                   |
| Metric aggregation initialization | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-metric-agg-init-context)     | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/aggregations/search-aggregations-metrics-scripted-metric-aggregation)  |
| Metric aggregation map            | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-metric-agg-map-context)      | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/aggregations/search-aggregations-metrics-scripted-metric-aggregation)  |
| Metric aggregation combine        | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-metric-agg-combine-context)  | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/aggregations/search-aggregations-metrics-scripted-metric-aggregation)  |
| Metric aggregation reduce         | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-metric-agg-reduce-context)   | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/aggregations/search-aggregations-metrics-scripted-metric-aggregation)  |
| Bucket script aggregation         | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-bucket-script-agg-context)   | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/aggregations/search-aggregations-pipeline-bucket-script-aggregation)   |
| Bucket selector aggregation       | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-bucket-selector-agg-context) | [Elasticsearch Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/aggregations/search-aggregations-pipeline-bucket-selector-aggregation) |
| Watcher condition                 | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-watcher-condition-context)   | [Elasticsearch Documentation](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/2395/explore-analyze/alerts-cases/watcher/condition-script)              |
| Watcher transform                 | [Painless Documentation](https://www.elastic.co/elastic/docs-builder/docs/2395/reference/scripting-languages/painless/painless-watcher-transform-context)   | [Elasticsearch Documentation](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/2395/explore-analyze/alerts-cases/watcher/transform-script)              |