Skip to content

Commit 42241ef

Browse files
committed
Address Shaina's feedback
1 parent 12137d5 commit 42241ef

File tree

9 files changed

+74
-96
lines changed

9 files changed

+74
-96
lines changed

explore-analyze/alerts-cases/watcher/how-watcher-works.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Deactivating a watch also enables you to keep it around for future use without d
184184

185185
You can use scripts and templates when defining a watch. Scripts and templates can reference elements in the watch execution context, including the watch payload. The execution context defines variables you can use in a script and parameter placeholders in a template.
186186

187-
{{watcher}} uses the Elasticsearch script infrastructure, which supports [inline](#inline-templates-scripts) and [stored](#stored-templates-scripts). Scripts and templates are compiled and cached by Elasticsearch to optimize recurring execution. Autoloading is also supported. For more information, see [Scripting](../../scripting.md) and [*How to write scripts*](../../scripting/modules-scripting-using.md).
187+
{{watcher}} uses the Elasticsearch script infrastructure, which supports [inline](#inline-templates-scripts) and [stored](#stored-templates-scripts). Scripts and templates are compiled and cached by Elasticsearch to optimize recurring execution. Autoloading is also supported. For more information, see [Scripting](../../scripting.md) and [*How to write Painless scripts*](../../scripting/modules-scripting-using.md).
188188

189189

190190
### Watch execution context [watch-execution-context]
-214 KB
Binary file not shown.

explore-analyze/scripting/common-script-uses.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ products:
1212

1313
You can write a script to do almost anything, and sometimes, that’s the challenge. It’s difficult to know what’s possible with scripts, so these tutorials address common use cases where scripts are particularly helpful.
1414

15-
Painless scripting becomes powerful when applied to real-world scenarios. These tutorials walk you through essential patterns and operations, providing working examples you can modify for your specific use cases.
16-
17-
# Available tutorials
15+
Painless scripting becomes powerful when applied to real-world scenarios. These tutorials walk you through essential patterns and operations, providing working examples you can modify for your specific use cases.
1816

1917
* [Accessing document fields and special variables](/explore-analyze/scripting/modules-scripting-fields.md)
2018
* [Accessing fields in a document](/explore-analyze/scripting/script-fields-api.md)
Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
navigation_title: Painless
23
mapped_pages:
34
- https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-painless.html
45
applies_to:
@@ -11,10 +12,10 @@ products:
1112
# Introduction to Painless [modules-scripting-painless]
1213

1314
:::{tip}
14-
This introduction is designed for users new to Painless scripting. If you're already familiar with Painless, refer to the [Painless Language Specification](elasticsearch://reference/scripting-languages/painless/painless-language-specification.md) for syntax details and advanced features.
15+
This introduction is designed for users new to Painless scripting. If you're already familiar with Painless, refer to the [Painless language specification](elasticsearch://reference/scripting-languages/painless/painless-language-specification.md) for syntax details and advanced features.
1516
:::
1617

17-
Painless is a secure, performant, and flexible scripting language designed specifically for {{es}}. As the default scripting language for {{es}}, Painless lets you safely customize search behavior, data processing, and operations workflows across your Elastic Stack deployments.
18+
Painless is a secure, performant, and flexible scripting language designed specifically for {{es}}. As the default scripting language for {{es}}, Painless lets you safely customize search behavior, data processing, and operations workflows across your {[stack]} deployments.
1819

1920
## What is Painless?
2021

@@ -24,7 +25,7 @@ Unlike general scripting languages, Painless is purpose-built for {{es}}, enabli
2425

2526
Common use cases include creating new fields based on existing data, calculating time differences between dates, extracting structured data from log messages, and implementing custom business logic in search scoring. For more examples, refer to our step-by-step [tutorials](/explore-analyze/scripting/common-script-uses.md).
2627

27-
## What are the benefits of Painless?
28+
## Benefits
2829

2930
Painless enables scripting in various contexts throughout {{es}}, such as:
3031

@@ -45,7 +46,7 @@ Painless enables scripting in various contexts throughout {{es}}, such as:
4546
* Monitor data patterns and trigger alerts with Watcher solutions
4647
* Transform alert payloads for targeted notifications and actions
4748

48-
## How does it work?
49+
## How it works
4950

5051
You can write Painless scripts inline for quick operations or create reusable functions for your data operation. Here’s a sample Painless script applied to data transformation:
5152

@@ -57,7 +58,7 @@ String productTitle(String manufacturer, String productName) {
5758
return productTitle("Elitelligence", "Winter jacket");
5859
```
5960

60-
This script demonstrates how Painless works with:
61+
This script demonstrates a few facets of Painless scripting:
6162

6263
* **Function definition:** Custom `productTitle` function with typed parameters
6364
* **Data types:** String and integer parameter handling
@@ -71,44 +72,17 @@ Painless provides three core benefits across all scripting contexts:
7172

7273
## Where to write in Painless
7374

74-
:::{image} /explore-analyze/images/elasticsearch-painless-where-to-write.png
75-
:alt: A graphic showing six different options of where to write Painless scripts
76-
:::
77-
7875
You can use Painless in multiple contexts throughout {{es}}:
7976

80-
* [**DevTools Console**](/explore-analyze/query-filter/tools/console.md)**:** for interactive script development and testing
81-
* [**Ingest Pipelines**](/manage-data/ingest/transform-enrich/ingest-pipelines.md)**:** for data transformation during indexing
77+
* [**Dev Tools Console**](/explore-analyze/query-filter/tools/console.md)**:** for interactive script development and testing
78+
* [**Ingest pipelines**](/manage-data/ingest/transform-enrich/ingest-pipelines.md)**:** for data transformation during indexing
8279
* [**Search queries**](/solutions/search.md)**:** for custom scoring and script fields
83-
* [**Runtime Fields**](/manage-data/data-store/mapping/runtime-fields.md)**:** for dynamic field creation
80+
* [**Runtime fields**](/manage-data/data-store/mapping/runtime-fields.md)**:** for dynamic field creation
8481
* [**Update API:**](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update) for document modification
8582
* [**Watcher**](/explore-analyze/alerts-cases/watcher.md)**:** for alert conditions and actions
8683

8784
## Start scripting
8885

89-
Write your first Painless script by trying out our How to write scripts or jump into Common script use cases for real-world examples using sample data.
90-
91-
For complete syntax and language features, refer to the [Painless Language Specification](elasticsearch://reference/scripting-languages/painless/painless-language-specification.md).
92-
93-
94-
<!--
95-
96-
# Painless scripting language [modules-scripting-painless]
97-
98-
*Painless* is a performant, secure scripting language designed specifically for {{es}}. You can use Painless to safely write inline and stored scripts anywhere scripts are supported in {{es}}.
99-
100-
$$$painless-features$$$
101-
Painless provides numerous capabilities that center around the following core principles:
102-
103-
* **Safety**: Ensuring the security of your cluster is of utmost importance. To that end, Painless uses a fine-grained allowlist with a granularity down to the members of a class. Anything that is not part of the allowlist results in a compilation error. See the [Painless API Reference](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference.html) for a complete list of available classes, methods, and fields per script context.
104-
* **Performance**: Painless compiles directly into JVM bytecode to take advantage of all possible optimizations that the JVM provides. Also, Painless typically avoids features that require additional slower checks at runtime.
105-
* **Simplicity**: Painless implements a syntax with a natural familiarity to anyone with some basic coding experience. Painless uses a subset of Java syntax with some additional improvements to enhance readability and remove boilerplate.
106-
107-
108-
## Start scripting [_start_scripting]
109-
110-
Ready to start scripting with Painless? Learn how to [write your first script](modules-scripting-using.md).
111-
112-
If you’re already familiar with Painless, see the [Painless Language Specification](elasticsearch://reference/scripting-languages/painless/painless-language-specification.md) for a detailed description of the Painless syntax and language features.
86+
Write your first Painless script by trying out our [guide](/explore-analyze/scripting/modules-scripting-using.md) or jump into one of our [tutorials](/explore-analyze/scripting/common-script-uses.md) for real-world examples using sample data.
11387

114-
-->
88+
For complete syntax and language features, refer to the [Painless language specification](elasticsearch://reference/scripting-languages/painless/painless-language-specification.md).

explore-analyze/scripting/modules-scripting-security.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ products:
1212

1313
As part of its core design, Painless provides secure scripting capabilities across {{es}}.
1414

15-
## Why Painless is Safe
16-
1715
Introduced in [{{es}} 5.0](https://www.elastic.co/blog/painless-a-new-scripting-language) as a replacement for Groovy, Painless is purpose-built for {{es}}, enabling native performance while preventing unauthorized access to system resources.
1816

1917
By operating in a controlled sandbox environment, Painless ensures that you won’t get compromised when using it. Painless only allows pre-approved operations through fine-grained allowlists. Scripts cannot access file systems, networks, or other system resources that could compromise your cluster while still providing the flexibility you need for search scoring, data processing, and operational automation.
@@ -27,17 +25,17 @@ By operating in a controlled sandbox environment, Painless ensures that you won
2725

2826
The fine-grained allowlist operates as the **first security layer**. Anything that is not part of the allowlist will result in a compilation error.
2927

30-
The **second layer of security** is [Java Security Manager(JSM)](https://www.oracle.com/java/technologies/javase/seccodeguide.html). As part of its startup sequence, {{es}} enables JSM to limit the actions that portions of the code can take. Painless uses this additional layer of defense to prevent scripts from doing things such as writing files and listening to sockets.
28+
The **second layer of security** is [Java Security Manager (JSM)](https://www.oracle.com/java/technologies/javase/seccodeguide.html). As part of its startup sequence, {{es}} enables JSM to limit the actions that portions of the code can take. Painless uses this additional layer of defense to prevent scripts from doing things such as writing files and listening to sockets.
3129

3230
{{es}} uses [Seccomp](https://en.wikipedia.org/wiki/Seccomp) in Linux, [Seatbelt](https://www.chromium.org/developers/design-documents/sandbox/osx-sandboxing-design) in macOS, and [ActiveProcessLimit](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684147) on Windows as **additional security layers** to prevent {{es}} from forking or running other processes.
3331

3432
Finally, scripts used in [scripted metrics aggregations](elasticsearch://reference/aggregations/search-aggregations-metrics-scripted-metric-aggregation.md) can be restricted to a defined list of scripts or forbidden altogether. This can prevent users from running particularly slow or resource-intensive aggregation queries.
3533

36-
You can modify the ***allowed script types setting*** to restrict the type of scripts that are allowed to run and control the available [contexts](elasticsearch://reference/scripting-languages/painless/painless-contexts.md) that scripts can run in. To implement additional layers in your defense-in-depth strategy, follow the [{{es}} security principles](/deploy-manage/security.md).
34+
You can modify the allowed script types setting to restrict the type of scripts that are allowed to run and control the available [contexts](elasticsearch://reference/scripting-languages/painless/painless-contexts.md) that scripts can run in. As well, you can use the {{es}} [security features](/deploy-manage/security.md) to enhance your defence strategy.
3735

3836
## Allowed script types setting [allowed-script-types-setting]
3937

40-
{{es}} supports two script types: `inline` and `stored`. By default, {{es}} is configured to run both types of scripts. To limit what type of scripts are run, set `script.allowed_types` to `inline` or `stored`. To prevent any scripts from running, set `script.allowed_types` to `none`. If you use Kibana, set \`script.allowed\_types\` to both or just \`inline\`. Some Kibana features rely on inline scripts and do not function as expected if {{es}} does not allow inline scripts.
38+
{{es}} supports two script types: `inline` and `stored`. By default, {{es}} is configured to run both types of scripts. To limit what type of scripts are run, set `script.allowed_types` to `inline` or `stored`. To prevent any scripts from running, set `script.allowed_types` to `none`. If you use Kibana, set `script.allowed_types` to both or just `inline`. Some Kibana features rely on inline scripts and do not function as expected if {{es}} does not allow inline scripts.
4139

4240
For example, to run `inline` scripts but not `stored` scripts:
4341

explore-analyze/scripting/modules-scripting-using.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ products:
88
- id: elasticsearch
99
---
1010

11-
# How to write scripts [modules-scripting-using]
11+
# How to write Painless scripts [modules-scripting-using]
1212

1313
:::{tip}
1414
This guide provides a beginner-friendly introduction to Painless scripting with step-by-step tutorials and practical examples. If you're new to scripting or Painless, this is the recommended starting point.

explore-analyze/scripting/modules-scripting-write-first-script.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,41 @@ A Painless script is structured as one or more statements and optionally has one
1414

1515
The [Painless execute API](elasticsearch://reference/scripting-languages/painless/painless-api-examples.md) provides the ability to test a script with simple user-defined parameters and receive a result. Let’s start with a complete script and review its constituent parts.
1616

17-
First, index a document with a single field so that we have some data to work with:
18-
19-
```console
20-
PUT my-index-000001/_doc/1
21-
{
22-
"my_field": 5
23-
}
24-
```
25-
26-
We can then construct a script that operates on that field and run evaluate the script as part of a query. The following query uses the [`script_fields`](elasticsearch://reference/elasticsearch/rest-apis/retrieve-selected-fields.md#script-fields) parameter of the search API to retrieve a script valuation. There’s a lot happening here, but we’ll break it down the components to understand them individually. For now, you only need to understand that this script takes `my_field` and operates on it.
27-
28-
```console
29-
GET my-index-000001/_search
30-
{
31-
"script_fields": {
32-
"my_doubled_field": {
33-
"script": { <1>
34-
"source": "doc['my_field'].value * params['multiplier']", <2>
35-
"params": {
36-
"multiplier": 2
17+
1. Index a document
18+
19+
Index a document with a single field so that we have some data to work with:
20+
21+
```console
22+
PUT my-index-000001/_doc/1
23+
{
24+
"my_field": 5
25+
}
26+
```
27+
28+
1. Operate on a field
29+
30+
You can now construct a script that operates on that field and then evaluate the script as part of a query. The following query uses the [`script_fields`](elasticsearch://reference/elasticsearch/rest-apis/retrieve-selected-fields.md#script-fields) parameter of the search API to retrieve a script valuation.
31+
32+
The components of this script are detailed in later pages. For now, note that the script takes `my_field` as input and operates on it.
33+
34+
```console
35+
GET my-index-000001/_search
36+
{
37+
"script_fields": {
38+
"my_doubled_field": {
39+
"script": { <1>
40+
"source": "doc['my_field'].value * params['multiplier']", <2>
41+
"params": {
42+
"multiplier": 2
43+
}
44+
}
3745
}
3846
}
3947
}
40-
}
41-
}
42-
```
48+
```
4349

44-
1. `script` object
45-
2. `script` source
50+
1. `script` object
51+
2. `script` source
4652

4753

48-
The `script` is a standard JSON object that defines scripts under most APIs in {{es}}. This object requires `source` to define the script itself. The script doesn’t specify a language, so it defaults to Painless.
54+
The `script` is a standard JSON object that defines scripts under most APIs in {{es}}. This object requires `source` to define the script itself. Since `script` isn't set, the [scripting language](/explore-analyze/scripting.md) is interpreted as being Painless, by default.

explore-analyze/scripting/painless-syntax-context-bridge.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you're new to Painless contexts, refer to [Painless contexts](elasticsearch:/
1717

1818
## Technical differences
1919

20-
* [**`doc` values**](#when-to-use-doc-values)) use columnar field value store enabled by default on all the fields except analyzed text fields. They can only return simple field values such as numbers, dates, geo-points, and terms.
20+
* [**`doc` values**](#when-to-use-doc-values) are a columnar field value store, enabled by default on all the fields except analyzed text fields. They can only return simple field values such as numbers, dates, geo-points, and terms.
2121
* [**`ctx` access**](#when-to-use-ctx) provides structured access to document content during modification contexts, with fields accessible as map and list structures for existing document fields.
2222
* [**`_source` access**](#when-to-use-source) loads the complete document as a map-of-maps, optimized for returning several fields per result but slower than doc values for single field access.
2323

@@ -132,7 +132,7 @@ POST /kibana_sample_data_ecommerce/_update_by_query
132132

133133
## Next steps
134134

135-
* **New users:** Explore Accessing [Accessing document fields and special variables](/explore-analyze/scripting/modules-scripting-fields.md)
135+
* **New users:** Explore [Accessing document fields and special variables](/explore-analyze/scripting/modules-scripting-fields.md)
136136
* **Advanced users:** Review [Painless contexts](elasticsearch://reference/scripting-languages/painless/painless-contexts.md) for context-specific implementation details
137137

138138

0 commit comments

Comments
 (0)