You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: explore-analyze/alerts-cases/watcher/how-watcher-works.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -184,7 +184,7 @@ Deactivating a watch also enables you to keep it around for future use without d
184
184
185
185
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.
186
186
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).
Copy file name to clipboardExpand all lines: explore-analyze/scripting/common-script-uses.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,7 @@ products:
12
12
13
13
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.
14
14
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.
18
16
19
17
*[Accessing document fields and special variables](/explore-analyze/scripting/modules-scripting-fields.md)
20
18
*[Accessing fields in a document](/explore-analyze/scripting/script-fields-api.md)
# Introduction to Painless [modules-scripting-painless]
12
13
13
14
:::{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.
15
16
:::
16
17
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.
18
19
19
20
## What is Painless?
20
21
@@ -24,7 +25,7 @@ Unlike general scripting languages, Painless is purpose-built for {{es}}, enabli
24
25
25
26
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).
26
27
27
-
## What are the benefits of Painless?
28
+
## Benefits
28
29
29
30
Painless enables scripting in various contexts throughout {{es}}, such as:
30
31
@@ -45,7 +46,7 @@ Painless enables scripting in various contexts throughout {{es}}, such as:
45
46
* Monitor data patterns and trigger alerts with Watcher solutions
46
47
* Transform alert payloads for targeted notifications and actions
47
48
48
-
## How does it work?
49
+
## How it works
49
50
50
51
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:
:alt: A graphic showing six different options of where to write Painless scripts
76
-
:::
77
-
78
75
You can use Painless in multiple contexts throughout {{es}}:
79
76
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
82
79
*[**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
84
81
*[**Update API:**](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update) for document modification
85
82
*[**Watcher**](/explore-analyze/alerts-cases/watcher.md)**:** for alert conditions and actions
86
83
87
84
## Start scripting
88
85
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.
113
87
114
-
-->
88
+
For complete syntax and language features, refer to the [Painless language specification](elasticsearch://reference/scripting-languages/painless/painless-language-specification.md).
Copy file name to clipboardExpand all lines: explore-analyze/scripting/modules-scripting-security.md
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,6 @@ products:
12
12
13
13
As part of its core design, Painless provides secure scripting capabilities across {{es}}.
14
14
15
-
## Why Painless is Safe
16
-
17
15
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.
18
16
19
17
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
27
25
28
26
The fine-grained allowlist operates as the **first security layer**. Anything that is not part of the allowlist will result in a compilation error.
29
27
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.
31
29
32
30
{{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.
33
31
34
32
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.
35
33
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.
{{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.
41
39
42
40
For example, to run `inline` scripts but not `stored` scripts:
Copy file name to clipboardExpand all lines: explore-analyze/scripting/modules-scripting-using.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ products:
8
8
- id: elasticsearch
9
9
---
10
10
11
-
# How to write scripts [modules-scripting-using]
11
+
# How to write Painless scripts [modules-scripting-using]
12
12
13
13
:::{tip}
14
14
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.
Copy file name to clipboardExpand all lines: explore-analyze/scripting/modules-scripting-write-first-script.md
+32-26Lines changed: 32 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,35 +14,41 @@ A Painless script is structured as one or more statements and optionally has one
14
14
15
15
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.
16
16
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.
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.
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.
Copy file name to clipboardExpand all lines: explore-analyze/scripting/painless-syntax-context-bridge.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ If you're new to Painless contexts, refer to [Painless contexts](elasticsearch:/
17
17
18
18
## Technical differences
19
19
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.
21
21
*[**`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.
22
22
*[**`_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.
23
23
@@ -132,7 +132,7 @@ POST /kibana_sample_data_ecommerce/_update_by_query
132
132
133
133
## Next steps
134
134
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)
136
136
***Advanced users:** Review [Painless contexts](elasticsearch://reference/scripting-languages/painless/painless-contexts.md) for context-specific implementation details
0 commit comments