Skip to content

Commit c59fbb3

Browse files
authored
Reorganize Painless doc structure (#42303)
1 parent 5f9c8ba commit c59fbb3

32 files changed

+120
-94
lines changed

docs/painless/index.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
include::../Versions.asciidoc[]
55

6-
include::painless-getting-started.asciidoc[]
6+
include::painless-guide.asciidoc[]
77

88
include::painless-lang-spec.asciidoc[]
99

docs/painless/painless-contexts.asciidoc

-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,4 @@ specialized code may define new ways to use a Painless script.
5454
| {xpack-ref}/transform-script.html[Elasticsearch Documentation]
5555
|====
5656

57-
include::painless-contexts/painless-context-examples.asciidoc[]
58-
5957
include::painless-contexts/index.asciidoc[]

docs/painless/painless-contexts/index.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include::painless-context-examples.asciidoc[]
2+
13
include::painless-ingest-processor-context.asciidoc[]
24

35
include::painless-update-context.asciidoc[]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
[[painless-guide]]
2+
== Painless Guide
3+
14
_Painless_ is a simple, secure scripting language designed specifically for use
25
with Elasticsearch. It is the default scripting language for Elasticsearch and
3-
can safely be used for inline and stored scripts. For a detailed description of
4-
the Painless syntax and language features, see the
5-
{painless}/painless-lang-spec.html[Painless Language Specification].
6+
can safely be used for inline and stored scripts. For a jump start into
7+
Painless, see <<painless-walkthrough, A Brief Painless Walkthrough>>. For a
8+
detailed description of the Painless syntax and language features, see the
9+
<<painless-lang-spec, Painless Language Specification>>.
610

7-
[[painless-features]]
8-
You can use Painless anywhere scripts can be used in Elasticsearch. Painless
11+
You can use Painless anywhere scripts are used in Elasticsearch. Painless
912
provides:
1013

1114
* Fast performance: Painless scripts https://benchmarks.elastic.co/index.html#search_qps_scripts[
@@ -18,7 +21,9 @@ complete list of available classes and methods.
1821
* Optional typing: Variables and parameters can use explicit types or the
1922
dynamic `def` type.
2023

21-
* Syntax: Extends Java's syntax to provide http://groovy-lang.org/index.html[
22-
Groovy-style] scripting language features that make scripts easier to write.
24+
* Syntax: Extends a subset of Java's syntax to provide additional scripting
25+
language features.
2326

2427
* Optimizations: Designed specifically for Elasticsearch scripting.
28+
29+
include::painless-guide/index.asciidoc[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include::painless-walkthrough.asciidoc[]
2+
3+
include::painless-method-dispatch.asciidoc[]
4+
5+
include::painless-debugging.asciidoc[]
6+
7+
include::painless-execute-script.asciidoc[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[[modules-scripting-painless-dispatch]]
2+
=== How painless dispatches functions
3+
4+
Painless uses receiver, name, and https://en.wikipedia.org/wiki/Arity[arity]
5+
for method dispatch. For example, `s.foo(a, b)` is resolved by first getting
6+
the class of `s` and then looking up the method `foo` with two parameters. This
7+
is different from Groovy which uses the
8+
https://en.wikipedia.org/wiki/Multiple_dispatch[runtime types] of the
9+
parameters and Java which uses the compile time types of the parameters.
10+
11+
The consequence of this that Painless doesn't support overloaded methods like
12+
Java, leading to some trouble when it whitelists classes from the Java
13+
standard library. For example, in Java and Groovy, `Matcher` has two methods:
14+
`group(int)` and `group(String)`. Painless can't whitelist both of these methods
15+
because they have the same name and the same number of parameters. So instead it
16+
has `group(int)` and `namedGroup(String)`.
17+
18+
We have a few justifications for this different way of dispatching methods:
19+
20+
1. It makes operating on `def` types simpler and, presumably, faster. Using
21+
receiver, name, and arity means that when Painless sees a call on a `def` object it
22+
can dispatch the appropriate method without having to do expensive comparisons
23+
of the types of the parameters. The same is true for invocations with `def`
24+
typed parameters.
25+
2. It keeps things consistent. It would be genuinely weird for Painless to
26+
behave like Groovy if any `def` typed parameters were involved and Java
27+
otherwise. It'd be slow for it to behave like Groovy all the time.
28+
3. It keeps Painless maintainable. Adding the Java or Groovy like method
29+
dispatch *feels* like it'd add a ton of complexity which'd make maintenance and
30+
other improvements much more difficult.

docs/painless/painless-getting-started.asciidoc renamed to docs/painless/painless-guide/painless-walkthrough.asciidoc

+4-44
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
[[painless-getting-started]]
2-
== Getting Started with Painless
3-
4-
include::painless-description.asciidoc[]
5-
6-
[[painless-examples]]
7-
=== Painless Examples
1+
[[painless-walkthrough]]
2+
=== A Brief Painless Walkthrough
83

94
To illustrate how Painless works, let's load some hockey stats into an Elasticsearch index:
105

@@ -121,7 +116,7 @@ GET hockey/_search
121116

122117

123118
[float]
124-
===== Missing values
119+
==== Missing values
125120

126121
`doc['field'].value` throws an exception if
127122
the field is missing in a document.
@@ -198,7 +193,7 @@ POST hockey/_update/1
198193
==== Dates
199194

200195
Date fields are exposed as
201-
`ReadableDateTime`, so they support methods like `getYear`, `getDayOfWeek`
196+
`ZonedDateTime`, so they support methods like `getYear`, `getDayOfWeek`
202197
or e.g. getting milliseconds since epoch with `getMillis`. To use these
203198
in a script, leave out the `get` prefix and continue with lowercasing the
204199
rest of the method name. For example, the following returns every hockey
@@ -365,38 +360,3 @@ Note: all of the `_update_by_query` examples above could really do with a
365360
{ref}/query-dsl-script-query.html[script query] it wouldn't be as efficient
366361
as using any other query because script queries aren't able to use the inverted
367362
index to limit the documents that they have to check.
368-
369-
[[modules-scripting-painless-dispatch]]
370-
=== How painless dispatches functions
371-
372-
Painless uses receiver, name, and https://en.wikipedia.org/wiki/Arity[arity]
373-
for method dispatch. For example, `s.foo(a, b)` is resolved by first getting
374-
the class of `s` and then looking up the method `foo` with two parameters. This
375-
is different from Groovy which uses the
376-
https://en.wikipedia.org/wiki/Multiple_dispatch[runtime types] of the
377-
parameters and Java which uses the compile time types of the parameters.
378-
379-
The consequence of this that Painless doesn't support overloaded methods like
380-
Java, leading to some trouble when it whitelists classes from the Java
381-
standard library. For example, in Java and Groovy, `Matcher` has two methods:
382-
`group(int)` and `group(String)`. Painless can't whitelist both of these methods
383-
because they have the same name and the same number of parameters. So instead it
384-
has `group(int)` and `namedGroup(String)`.
385-
386-
We have a few justifications for this different way of dispatching methods:
387-
388-
1. It makes operating on `def` types simpler and, presumably, faster. Using
389-
receiver, name, and arity means that when Painless sees a call on a `def` object it
390-
can dispatch the appropriate method without having to do expensive comparisons
391-
of the types of the parameters. The same is true for invocations with `def`
392-
typed parameters.
393-
2. It keeps things consistent. It would be genuinely weird for Painless to
394-
behave like Groovy if any `def` typed parameters were involved and Java
395-
otherwise. It'd be slow for it to behave like Groovy all the time.
396-
3. It keeps Painless maintainable. Adding the Java or Groovy like method
397-
dispatch *feels* like it'd add a ton of complexity which'd make maintenance and
398-
other improvements much more difficult.
399-
400-
include::painless-debugging.asciidoc[]
401-
402-
include::painless-execute-script.asciidoc[]

docs/painless/painless-lang-spec.asciidoc

+1-35
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,4 @@ into Java Virtual Machine (JVM) byte code and executed against a standard JVM.
1717
This specification uses ANTLR4 grammar notation to describe the allowed syntax.
1818
However, the actual Painless grammar is more compact than what is shown here.
1919

20-
include::painless-comments.asciidoc[]
21-
22-
include::painless-keywords.asciidoc[]
23-
24-
include::painless-literals.asciidoc[]
25-
26-
include::painless-identifiers.asciidoc[]
27-
28-
include::painless-variables.asciidoc[]
29-
30-
include::painless-types.asciidoc[]
31-
32-
include::painless-casting.asciidoc[]
33-
34-
include::painless-operators.asciidoc[]
35-
36-
include::painless-operators-general.asciidoc[]
37-
38-
include::painless-operators-numeric.asciidoc[]
39-
40-
include::painless-operators-boolean.asciidoc[]
41-
42-
include::painless-operators-reference.asciidoc[]
43-
44-
include::painless-operators-array.asciidoc[]
45-
46-
include::painless-statements.asciidoc[]
47-
48-
include::painless-scripts.asciidoc[]
49-
50-
include::painless-functions.asciidoc[]
51-
52-
include::painless-lambdas.asciidoc[]
53-
54-
include::painless-regexes.asciidoc[]
20+
include::painless-lang-spec/index.asciidoc[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
include::painless-comments.asciidoc[]
2+
3+
include::painless-keywords.asciidoc[]
4+
5+
include::painless-literals.asciidoc[]
6+
7+
include::painless-identifiers.asciidoc[]
8+
9+
include::painless-variables.asciidoc[]
10+
11+
include::painless-types.asciidoc[]
12+
13+
include::painless-casting.asciidoc[]
14+
15+
include::painless-operators.asciidoc[]
16+
17+
include::painless-operators-general.asciidoc[]
18+
19+
include::painless-operators-numeric.asciidoc[]
20+
21+
include::painless-operators-boolean.asciidoc[]
22+
23+
include::painless-operators-reference.asciidoc[]
24+
25+
include::painless-operators-array.asciidoc[]
26+
27+
include::painless-statements.asciidoc[]
28+
29+
include::painless-scripts.asciidoc[]
30+
31+
include::painless-functions.asciidoc[]
32+
33+
include::painless-lambdas.asciidoc[]
34+
35+
include::painless-regexes.asciidoc[]

docs/painless/painless-xref.asciidoc

-2
This file was deleted.

docs/reference/ingest/ingest-node.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ template for all indexes that hold data that needs pre-index processing.
563563
[[conditionals-with-regex]]
564564
=== Conditionals with the Regular Expressions
565565
The `if` conditional is implemented as a Painless script, which requires
566-
{painless}//painless-examples.html#modules-scripting-painless-regex[explicit support for regular expressions].
566+
{painless}//painless-regexes.html[explicit support for regular expressions].
567567

568568
`script.painless.regex.enabled: true` must be set in `elasticsearch.yml` to use regular
569569
expressions in the `if` condition.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
[[modules-scripting-painless]]
22
=== Painless Scripting Language
33

4-
include::../../../painless/painless-description.asciidoc[]
4+
_Painless_ is a simple, secure scripting language designed specifically for use
5+
with Elasticsearch. It is the default scripting language for Elasticsearch and
6+
can safely be used for inline and stored scripts. To get started with
7+
Painless, see the {painless}/painless-guide.html[Painless Guide]. For a
8+
detailed description of the Painless syntax and language features, see the
9+
{painless}/painless-lang-spec.html[Painless Language Specification].
510

6-
Ready to start scripting with Painless? See {painless}/painless-getting-started.html[Getting Started with Painless] in the guide to the
11+
[[painless-features]]
12+
You can use Painless anywhere scripts can be used in Elasticsearch. Painless
13+
provides:
14+
15+
* Fast performance: Painless scripts https://benchmarks.elastic.co/index.html#search_qps_scripts[
16+
run several times faster] than the alternatives.
17+
18+
* Safety: Fine-grained whitelist with method call/field granularity. See the
19+
{painless}/painless-api-reference.html[Painless API Reference] for a
20+
complete list of available classes and methods.
21+
22+
* Optional typing: Variables and parameters can use explicit types or the
23+
dynamic `def` type.
24+
25+
* Syntax: Extends a subset of Java's syntax to provide additional scripting
26+
language features.
27+
28+
* Optimizations: Designed specifically for Elasticsearch scripting.
29+
30+
Ready to start scripting with Painless? See the
31+
{painless}/painless-guide.html[Painless Guide] for the
732
{painless}/index.html[Painless Scripting Language].

0 commit comments

Comments
 (0)