Skip to content

[DOCS] [7.x] Focus scripting docs on Painless (#69748) #70588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/painless/painless-guide/painless-datetime.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ source document, or from an indexed document.

===== Datetime Input From User Parameters

Use the {ref}/modules-scripting-using.html#_script_parameters[params section]
Use the {ref}/modules-scripting-using.html[params section]
during script specification to pass in a numeric datetime or string datetime as
a script input. Access to user-defined parameters within a script is dependent
on the Painless context, though, the parameters are most commonly accessible
Expand Down
79 changes: 32 additions & 47 deletions docs/painless/painless-lang-spec/painless-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,38 @@ type). Use the <<field-access-operator, field access operator>> or
<<method-call-operator, method call operator>> on a primitive type value to
force evaluation as its corresponding reference type value.

The following primitive types are available:

[horizontal]
`byte`::
8-bit, signed, two's complement integer
* range: [`-128`, `127`]
* default value: `0`
* reference type: `Byte`

`short`::
16-bit, signed, two's complement integer
* range: [`-32768`, `32767`]
* default value: `0`
* reference type: `Short`

`char`::
16-bit, unsigned, Unicode character
* range: [`0`, `65535`]
* default value: `0` or `\u0000`
* reference type: `Character`

`int`::
32-bit, signed, two's complement integer
* range: [`-2^31`, `2^31-1`]
* default value: `0`
* reference type: `Integer`

`long`::
64-bit, signed, two's complement integer
* range: [`-2^63`, `2^63-1`]
* default value: `0`
* reference type: `Long`

`float`::
32-bit, signed, single-precision, IEEE 754 floating point number
* default value: `0.0`
* reference type: `Float`

`double`::
64-bit, signed, double-precision, IEEE 754 floating point number
* default value: `0.0`
* reference type: `Double`

`boolean`::
logical quantity with two possible values of `true` and `false`
* default value: `false`
* reference type: `Boolean`
The following primitive types are available. The corresponding reference type
is listed in parentheses. For example, `Byte` is the reference type for the
`byte` primitive type:

[[available-primitive-types]]
.**Available primitive types**
[%collapsible%open]
====
`byte` (`Byte`)::
8-bit, signed, two's complement integer. Range: [`-128`, `127`]. Default: `0`.

`short` (`Short`)::
16-bit, signed, two's complement integer. Range: [`-32768`, `32767`]. Default: `0`.

`char` (`Character`)::
16-bit, unsigned, Unicode character. Range: [`0`, `65535`]. Default: `0` or `\u0000`.

`int` (`Integer`)::
32-bit, signed, two's complement integer. Range: [`-2^31`, `2^31-1`]. Default: `0`.

`long` (`Long`)::
64-bit, signed, two's complement integer. Range: [`-2^63`, `2^63-1`]. Default: `0`.

`float (`Float`)`::
32-bit, signed, single-precision, IEEE 754 floating point number. Default `0.0`.

`double` (`Double`)::
64-bit, signed, double-precision, IEEE 754 floating point number. Default: `0.0`.

`boolean` (`Boolean`)::
logical quantity with two possible values of `true` and `false`. Default: `false`.
====

*Examples*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Predicate script used to apply token filters. If a token
matches this script, the filters in the `filter` parameter are applied to the
token.

For valid parameters, see <<_script_parameters>>. Only inline scripts are
For valid parameters, see <<modules-scripting-using>>. Only inline scripts are
supported. Painless scripts are executed in the
{painless}/painless-analysis-predicate-context.html[analysis predicate context]
and require a `token` property.
Expand Down Expand Up @@ -145,4 +145,4 @@ PUT /palindrome_list
}
}
}
--------------------------------------------------
--------------------------------------------------
2 changes: 1 addition & 1 deletion docs/reference/ingest/processors/script.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ See <<modules-scripting-using, How to use scripts>> to learn more about writing
leverages caching of compiled scripts for improved performance. Since the
script specified within the processor is potentially re-compiled per document, it is important
to understand how script caching works. To learn more about
caching see <<modules-scripting-using-caching, Script Caching>>.
caching see <<scripts-and-search-speed, Script Caching>>.

[[script-options]]
.Script Options
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/redirects.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

The following pages have moved or been deleted.

[roles="exclude",id="modules-scripting-stored-scripts"]
=== Stored scripts

See <<script-stored-scripts,Store and retrieve scripts>>

[role="exclude",id="node.name"]
=== Node name setting

Expand Down
78 changes: 28 additions & 50 deletions docs/reference/scripting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,59 @@
[partintro]
--
With scripting, you can evaluate custom expressions in {es}. For example, you
could use a script to return "script fields" as part of a search request or
evaluate a custom score for a query.
can use a script to return a computed value as a field or evaluate a custom
score for a query.

The default scripting language is <<modules-scripting-painless, `Painless`>>.
Additional `lang` plugins enable you to run scripts written in other languages.
Everywhere a script can be used, you can include a `lang` parameter
to specify the language of the script.
The default scripting language is <<modules-scripting-painless,Painless>>.
Additional `lang` plugins are available to run scripts written in other
languages. You can specify the language of the script anywhere that scripts run.

[discrete]
== General-purpose languages
[[scripting-available-languages]]
== Available scripting languages

These languages can be used for any purpose in the scripting APIs,
and give the most flexibility.

[cols="<,<,<",options="header",]
|=======================================================================
|Language
|Sandboxed
|Required plugin

|<<modules-scripting-painless, `painless`>>
|yes
|built-in

|=======================================================================

[discrete]
== Special-purpose languages

These languages are less flexible, but typically have higher performance for
certain tasks.
Painless is purpose-built for {es}, can be used for any purpose in the
scripting APIs, and provides the most flexibility. The other languages are less
flexible, but can be useful for specific purposes.

[cols="<,<,<,<",options="header",]
|=======================================================================
|========
|Language
|Sandboxed
|Required plugin
|Purpose

|<<modules-scripting-painless,`painless`>>
|{yes-icon}
|Built-in
|Purpose-built for {es}

|<<modules-scripting-expression, `expression`>>
|yes
|built-in
|fast custom ranking and sorting
|{yes-icon}
|Built-in
|Fast custom ranking and sorting

|<<search-template, `mustache`>>
|yes
|built-in
|templates
|{yes-icon}
|Built-in
|Templates

|<<modules-scripting-engine, `java`>>
|n/a
|you write it!
|expert API

|=======================================================================

[WARNING]
.Scripts and security
=================================================

Languages that are sandboxed are designed with security in mind. However, non-
sandboxed languages can be a security issue, please read
<<modules-scripting-security, Scripting and security>> for more details.
|{no-icon}
|You write it!
|Expert API
|========

=================================================
--

include::scripting/painless.asciidoc[]

include::scripting/using.asciidoc[]

include::scripting/fields.asciidoc[]

include::scripting/security.asciidoc[]

include::scripting/painless.asciidoc[]

include::scripting/expression.asciidoc[]

include::scripting/engine.asciidoc[]
56 changes: 29 additions & 27 deletions docs/reference/scripting/painless.asciidoc
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
[[modules-scripting-painless]]
== Painless scripting language

_Painless_ is a simple, secure scripting language designed specifically for use
with Elasticsearch. It is the default scripting language for Elasticsearch and
can safely be used for inline and stored scripts. To get started with
Painless, see the {painless}/painless-guide.html[Painless Guide]. For a
detailed description of the Painless syntax and language features, see the
{painless}/painless-lang-spec.html[Painless Language Specification].
_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}.

[[painless-features]]
You can use Painless anywhere scripts can be used in Elasticsearch. Painless
provides:

* Fast performance: Painless scripts https://benchmarks.elastic.co/index.html#search_qps_scripts[
run several times faster] than the alternatives.

* Safety: Fine-grained allowlists with method call/field granularity. See the
{painless}/painless-api-reference.html[Painless API Reference] for a
complete list of available classes and methods.

* Optional typing: Variables and parameters can use explicit types or the
dynamic `def` type.

* Syntax: Extends a subset of Java's syntax to provide additional scripting
language features.

* Optimizations: Designed specifically for Elasticsearch scripting.

Ready to start scripting with Painless? See the
{painless}/painless-guide.html[Painless Guide] for the
{painless}/index.html[Painless Scripting Language].
Painless provides numerous capabilities that center around the following
core principles:

* **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}/painless-api-reference.html[Painless API Reference]
for a complete list of available classes, methods, and fields per script
context.
* **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.
* **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.

[discrete]
=== Start scripting
Ready to start scripting with Painless? Learn how to
<<modules-scripting-using,write your first script>>.

If you're already familiar with Painless, see the
{painless}/painless-lang-spec.html[Painless Language Specification] for a
detailed description of the Painless syntax and language features.
8 changes: 4 additions & 4 deletions docs/reference/scripting/security.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ security of the Elasticsearch deployment.
=== Allowed script types setting

Elasticsearch supports two script types: `inline` and `stored` (<<modules-scripting-using>>).
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`.
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`.

IMPORTANT: If you use {kib}, set `script.allowed_types` to `both` or `inline`.
Some {kib} features rely on inline scripts and do not function as expected
IMPORTANT: If you use {kib}, set `script.allowed_types` to `both` or `inline`.
Some {kib} features rely on inline scripts and do not function as expected
if {es} does not allow inline scripts.

For example, to run `inline` scripts but not `stored` scripts, specify:
Expand Down
Loading