Skip to content
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

Painless: Add Context Docs #31190

Merged
merged 116 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
153d376
Separate identifiers into its own section. Clean up variables.
jdconrad Apr 17, 2018
6729d5f
More docs.
jdconrad Apr 18, 2018
84048e4
Merge branch 'master' into docs1
jdconrad Apr 18, 2018
10fca6c
Merge branch 'master' into docs1
jdconrad Apr 18, 2018
c2c3448
Modify language used to describe shallow copies.
jdconrad Apr 19, 2018
1cdf013
Move examples into lists to make sections flow better when multiple
jdconrad Apr 19, 2018
862962b
Update primitive types.
jdconrad Apr 20, 2018
73883ac
Cleaned up reference types.
jdconrad Apr 24, 2018
7dfb034
Clean up dynamic types.
jdconrad Apr 24, 2018
75f1498
String and void type clean up.
jdconrad Apr 25, 2018
f75d50e
Merge branch 'master' into docs2
jdconrad Apr 25, 2018
956a188
Merge branch 'master' into docs2
jdconrad Apr 27, 2018
bce78ed
Fixes.
jdconrad Apr 28, 2018
b034cff
Merge branch 'master' into docs2
jdconrad Apr 30, 2018
e82a1e0
Clean up types section.
jdconrad May 1, 2018
1da1704
Merge branch 'master' into docs2
jdconrad May 1, 2018
48b3aee
Merge branch 'master' into docs3
jdconrad May 2, 2018
8bc0c74
Some casting and example clean up.
jdconrad May 4, 2018
275c2e7
Merge branch 'master' into docs3
jdconrad May 4, 2018
00ba531
Updated examples.
jdconrad May 4, 2018
7bcd114
More changes.
jdconrad May 7, 2018
84ea43d
Merge branch 'master' into docs3
jdconrad May 8, 2018
1cf2f0b
Merge branch 'master' into docs3
jdconrad May 9, 2018
68059ae
More example clean up.
jdconrad May 9, 2018
73a24f0
More casting clean up.
jdconrad May 9, 2018
c3fcd67
More clean up.
jdconrad May 10, 2018
19abc56
More changes.
jdconrad May 14, 2018
00cf5df
Merge branch 'master' into docs3
jdconrad May 14, 2018
0cb3e66
More fixes.
jdconrad May 14, 2018
bc4509f
Merge branch 'master' into docs3
jdconrad May 14, 2018
507ac48
More example clean up.
jdconrad May 15, 2018
7ad4ebb
More changes.
jdconrad May 15, 2018
a9c941e
Finished promotion and boxing/unboxing.
jdconrad May 15, 2018
0007d26
Merge branch 'master' into docs2
jdconrad May 15, 2018
988fc23
Cleaned up casting basic on PR comments.
jdconrad May 19, 2018
b95ce25
More changes.
jdconrad May 21, 2018
a8ed00b
Merge branch 'master' into docs2
jdconrad May 21, 2018
7b73010
More fixes.
jdconrad May 21, 2018
8fc4566
Fixed casting and types based on PR feedback.
jdconrad May 22, 2018
ca2bb83
Cleaned up more.
jdconrad May 22, 2018
ae1ae75
Extra blank lines at end of docs.
jdconrad May 22, 2018
a5cc47a
Merge branch 'master' into docs2
jdconrad May 22, 2018
7b70e15
Start of structural change for operators.
jdconrad May 22, 2018
093a10f
Moved operations to the appropriate pages.
jdconrad May 23, 2018
bb4dc1c
More clean up.
jdconrad May 23, 2018
8f9b09e
Merge branch 'master' into docs5
jdconrad May 24, 2018
a122212
Added a casting table.
jdconrad May 24, 2018
2665835
Switch assign/access to store/load in examples.
jdconrad May 24, 2018
aeb879b
Cleaned up some of the general operators.
jdconrad May 24, 2018
7165b0f
Merge branch 'master' into docs5
jdconrad May 29, 2018
ba4b7c1
Merge branch 'master' into docs5
jdconrad May 30, 2018
b0c2512
Merge branch 'master' into docs5
jdconrad May 31, 2018
b1d31d1
Clean up of general operators.
jdconrad May 31, 2018
246c824
Fix examples with load from instead of load.
jdconrad May 31, 2018
4e2b89d
Update structure for long-term spec goals.
jdconrad May 31, 2018
8b5316b
Merge branch 'master' into docs5
jdconrad May 31, 2018
8302de3
Clean up numerical operators.
jdconrad Jun 1, 2018
7ad8379
Merge branch 'master' into docs5
jdconrad Jun 1, 2018
1d64edd
Merge branch 'docs5' into docs6
jdconrad Jun 1, 2018
0696c83
Partially completed clean up of reference type operators.
jdconrad Jun 1, 2018
46a868e
Completion of clean up of reference type operators.
jdconrad Jun 2, 2018
15aac91
Clean up of array operators section.
jdconrad Jun 2, 2018
f85e235
Partially completed boolean operators clean up.
jdconrad Jun 2, 2018
6f16058
More clean up.
jdconrad Jun 2, 2018
775cfff
More clean up.
jdconrad Jun 2, 2018
610d67c
Completion of operators clean up.
jdconrad Jun 2, 2018
3b8da65
Fix Java to Painless.
jdconrad Jun 2, 2018
33b7357
Merge branch 'master' into docs5
jdconrad Jun 2, 2018
d17c365
Merge branch 'master' into docs5
jdconrad Jun 3, 2018
a2afc62
Merge branch 'docs5' into docs6
jdconrad Jun 3, 2018
8c87bf9
Merge branch 'docs6' into docs7
jdconrad Jun 3, 2018
5b19038
Merge branch 'docs7' into docs8
jdconrad Jun 3, 2018
46f737f
Merge branch 'docs8' into docs9
jdconrad Jun 3, 2018
e486275
Add structure for context information in Painless.
jdconrad Jun 3, 2018
9439b92
Fix missing lang.
jdconrad Jun 3, 2018
5aaa88a
Merge branch 'docs5' into docs6
jdconrad Jun 3, 2018
86591c3
Merge branch 'docs6' into docs7
jdconrad Jun 3, 2018
d54e4a0
Fix missing lang.
jdconrad Jun 3, 2018
23c2320
Merge branch 'docs7' into docs8
jdconrad Jun 3, 2018
fba0246
Merge branch 'docs8' into docs9
jdconrad Jun 3, 2018
6d84e12
Added some docs for update context.
jdconrad Jun 3, 2018
5a7257b
Added info for update and update by query contexts.
jdconrad Jun 4, 2018
73ff8a2
Fix missing lang.
jdconrad Jun 4, 2018
2b55029
Merge branch 'master' into docs5
jdconrad Jun 4, 2018
bdb8eb1
Merge branch 'docs5' into docs6
jdconrad Jun 4, 2018
4e2994a
Merge branch 'docs6' into docs7
jdconrad Jun 4, 2018
a570d37
Merge branch 'docs7' into docs8
jdconrad Jun 4, 2018
2e38982
Merge branch 'docs8' into docs9
jdconrad Jun 4, 2018
f2efb10
Merge branch 'docs9' into docs10
jdconrad Jun 4, 2018
493c06b
Minor correction.
jdconrad Jun 4, 2018
a8c037f
Added score, similarity, and weight context variables.
jdconrad Jun 4, 2018
a0c1bf6
More progress on contexts.
jdconrad Jun 4, 2018
c688199
Response to PR review.
jdconrad Jun 5, 2018
542f52e
Merge branch 'master' into docs5
jdconrad Jun 5, 2018
e0e7dce
Merge branch 'docs5' into docs6
jdconrad Jun 5, 2018
603e5e5
PR response to numeric operators.
jdconrad Jun 5, 2018
afdc961
Merge branch 'docs6' into docs7
jdconrad Jun 5, 2018
12fb54d
Response to PR comments for reference operators.
jdconrad Jun 5, 2018
c83ecaf
Merge branch 'docs7' into docs8
jdconrad Jun 5, 2018
be37bf1
Cleaned up array operators based on PR feedback.
jdconrad Jun 5, 2018
f0bd472
Merge branch 'docs8' into docs9
jdconrad Jun 5, 2018
c35e977
Clean up boolean operators based on PR feedback.
jdconrad Jun 5, 2018
0760a41
Accidentally left in modified test.
jdconrad Jun 5, 2018
8fdad77
Merge branch 'docs9' into docs10
jdconrad Jun 5, 2018
0c8925e
Merge branch 'docs5' into docs10
jdconrad Jun 5, 2018
cce74a5
Partial progress on aggs contexts.
jdconrad Jun 6, 2018
dd14914
Merge branch 'master' into docs10
jdconrad Jun 6, 2018
6a4e8de
Finished metric agg contexts.
jdconrad Jun 6, 2018
f182434
More changes.
jdconrad Jun 6, 2018
48033af
Finished transform context.
jdconrad Jun 6, 2018
d1366dc
Merge branch 'master' into docs10
jdconrad Jun 8, 2018
85af2a1
Bit of clean up.
jdconrad Jun 8, 2018
452cf50
Merge branch 'master' into docs10
jdconrad Jun 11, 2018
7659bb9
Merge branch 'master' into docs10
jdconrad Jun 27, 2018
55018e7
Merge branch 'master' into docs10
jdconrad Jul 2, 2018
18b35a5
Response to PR feedback.
jdconrad Jul 2, 2018
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
4 changes: 3 additions & 1 deletion docs/painless/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ include::painless-getting-started.asciidoc[]

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

include::painless-api-reference.asciidoc[]
include::painless-contexts.asciidoc[]

include::painless-api-reference.asciidoc[]
58 changes: 58 additions & 0 deletions docs/painless/painless-contexts.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[[painless-contexts]]
== Painless contexts

:es_version: https://www.elastic.co/guide/en/elasticsearch/reference/master
:xp_version: https://www.elastic.co/guide/en/x-pack/current

A Painless script is evaluated within a context. Each context has values that
are available as local variables, a whitelist that controls the available
classes, and the methods and fields within those classes (API), and
if and what type of value is returned.

A Painless script is typically executed within one of the contexts in the table
below. Note this is not necessarily a comprehensive list as custom plugins and
specialized code may define new ways to use a Painless script.

[options="header",cols="<1,<1,<1"]
|====
| Name | Painless Documentation
| Elasticsearch Documentation
| Update | <<painless-update-context, Painless Documentation>>
| {es_version}/docs-update.html[Elasticsearch Documentation]
| Update by query | <<painless-update-by-query-context, Painless Documentation>>
| {es_version}/docs-update-by-query.html[Elasticsearch Documentation]
| Reindex | <<painless-reindex-context, Painless Documentation>>
| {es_version}/docs-reindex.html[Elasticsearch Documentation]
| Sort | <<painless-sort-context, Painless Documentation>>
| {es_version}/search-request-sort.html[Elasticsearch Documentation]
| Similarity | <<painless-similarity-context, Painless Documentation>>
| {es_version}/index-modules-similarity.html[Elasticsearch Documentation]
| Weight | <<painless-similarity-context, Painless Documentation>>
| {es_version}/index-modules-similarity.html[Elasticsearch Documentation]
| Score | <<painless-score-context, Painless Documentation>>
| {es_version}/query-dsl-function-score-query.html[Elasticsearch Documentation]
| Field | <<painless-field-context, Painless Documentation>>
| {es_version}/search-request-script-fields.html[Elasticsearch Documentation]
| Filter | <<painless-filter-context, Painless Documentation>>
| {es_version}/query-dsl-script-query.html[Elasticsearch Documentation]
| Minimum should match | <<painless-min-should-match-context, Painless Documentation>>
| {es_version}/query-dsl-terms-set-query.html[Elasticsearch Documentation]
| Metric aggregation initialization | <<painless-metric-agg-init-context, Painless Documentation>>
| {es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Metric aggregation map | <<painless-metric-agg-map-context, Painless Documentation>>
| {es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Metric aggregation combine | <<painless-metric-agg-combine-context, Painless Documentation>>
| {es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Metric aggregation reduce | <<painless-metric-agg-reduce-context, Painless Documentation>>
| {es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[Elasticsearch Documentation]
| Bucket aggregation | <<painless-bucket-agg-context, Painless Documentation>>
| {es_version}/search-aggregations-pipeline-bucket-script-aggregation.html[Elasticsearch Documentation]
| Ingest processor | <<painless-ingest-processor-context, Painless Documentation>>
| {es_version}/script-processor.html[Elasticsearch Documentation]
| Watcher condition | <<painless-watcher-condition-context, Painless Documentation>>
| {xp_version}/condition-script.html[Elasticsearch Documentation]
| Watcher transform | <<painless-watcher-transform-context, Painless Documentation>>
| {xp_version}/transform-script.html[Elasticsearch Documentation]
|====

include::painless-contexts/index.asciidoc[]
35 changes: 35 additions & 0 deletions docs/painless/painless-contexts/index.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
include::painless-update-context.asciidoc[]

include::painless-update-by-query-context.asciidoc[]

include::painless-reindex-context.asciidoc[]

include::painless-sort-context.asciidoc[]

include::painless-similarity-context.asciidoc[]

include::painless-weight-context.asciidoc[]

include::painless-score-context.asciidoc[]

include::painless-field-context.asciidoc[]

include::painless-filter-context.asciidoc[]

include::painless-min-should-match-context.asciidoc[]

include::painless-metric-agg-init-context.asciidoc[]

include::painless-metric-agg-map-context.asciidoc[]

include::painless-metric-agg-combine-context.asciidoc[]

include::painless-metric-agg-reduce-context.asciidoc[]

include::painless-bucket-agg-context.asciidoc[]

include::painless-ingest-processor-context.asciidoc[]

include::painless-watcher-condition-context.asciidoc[]

include::painless-watcher-transform-context.asciidoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[painless-bucket-agg-context]]
=== Bucket aggregation context

Use a Painless script in an
{es_version}/search-aggregations-pipeline-bucket-script-aggregation.html[bucket aggregation]
to calculate a value as a result in a bucket.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query. The parameters
include values defined as part of the `buckets_path`.

*Return*

numeric::
The calculated value as the result.

*API*

The standard <<painless-api-reference, Painless API>> is available.
31 changes: 31 additions & 0 deletions docs/painless/painless-contexts/painless-field-context.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[painless-field-context]]
=== Field context

Use a Painless script to create a
{es_version}/search-request-script-fields.html[script field] to return
a customized value for each document in the results of a query.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`doc` (`Map`, read-only)::
Contains the fields of the specified document where each field is a
`List` of values.

{es_version}/mapping-source-field.html[`ctx['_source']`] (`Map`)::
Contains extracted JSON in a `Map` and `List` structure for the fields
existing in a stored document.

`_score` (`double` read-only)::
The original score of the specified document.

*Return*

`Object`::
The customized value for each document.

*API*

The standard <<painless-api-reference, Painless API>> is available.
26 changes: 26 additions & 0 deletions docs/painless/painless-contexts/painless-filter-context.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[[painless-filter-context]]
=== Filter context

Use a Painless script as a {es_version}/query-dsl-script-query.html[filter] in a
query to include and exclude documents.


*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`doc` (`Map`, read-only)::
Contains the fields of the current document where each field is a
`List` of values.

*Return*

`boolean`::
Return `true` if the current document should be returned as a result of
the query, and `false` otherwise.


*API*

The standard <<painless-api-reference, Painless API>> is available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[[painless-ingest-processor-context]]
=== Ingest processor context

Use a Painless script in an {es_version}/script-processor.html[ingest processor]
to modify documents upon insertion.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

{es_version}/mapping-index-field.html[`ctx['_index']`] (`String`)::
The name of the index.

{es_version}/mapping-type-field.html[`ctx['_type']`] (`String`)::
The type of document within an index.

`ctx` (`Map`)::
Contains extracted JSON in a `Map` and `List` structure for the fields
that are part of the document.

*Side Effects*

{es_version}/mapping-index-field.html[`ctx['_index']`]::
Modify this to change the destination index for the current document.

{es_version}/mapping-type-field.html[`ctx['_type']`]::
Modify this to change the type for the current document.

`ctx` (`Map`, read-only)::
Modify the values in the `Map/List` structure to add, modify, or delete
the fields of a document.

*Return*

void::
No expected return value.

*API*

The standard <<painless-api-reference, Painless API>> is available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[painless-metric-agg-combine-context]]
=== Metric aggregation combine context

Use a Painless script to
{es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[combine]
values for use in a scripted metric aggregation. A combine script is run once
per shard following a <<painless-metric-agg-map-context, map script>> and is
optional as part of a full metric aggregation.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`params['_agg']` (`Map`)::
`Map` with values available from the prior map script.

*Return*

`List`, `Map`, `String`, or primitive::
A value collected for use in a
<<painless-metric-agg-reduce-context, reduce script>>. If no reduce
script is specified, the value is used as part of the result.

*API*

The standard <<painless-api-reference, Painless API>> is available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[[painless-metric-agg-init-context]]
=== Metric aggregation initialization context

Use a Painless script to
{es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[initialize]
values for use in a scripted metric aggregation. An initialization script is
run prior to document collection once per shard and is optional as part of the
full metric aggregation.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`params['_agg']` (`Map`)::
Empty `Map` used to add values for use in a
<<painless-metric-agg-map-context, map script>>.

*Side Effects*

`params['_agg']` (`Map`)::
Add values to this `Map` to for use in a map. Additional values must
be of the type `Map`, `List`, `String` or primitive.

*Return*

`void`::
No expected return value.

*API*

The standard <<painless-api-reference, Painless API>> is available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[[painless-metric-agg-map-context]]
=== Metric aggregation map context

Use a Painless script to
{es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[map]
values for use in a scripted metric aggregation. A map script is run once per
collected document following an optional
<<painless-metric-agg-init-context, initialization script>> and is required as
part of a full metric aggregation.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`params['_agg']` (`Map`)::
`Map` used to add values for processing in a
<<painless-metric-agg-map-context, combine script>> or returned
directly.

`doc` (`Map`, read-only)::
Contains the fields of the current document where each field is a
`List` of values.

`_score` (`double` read-only)::
The similarity score of the current document.

*Side Effects*

`params['_agg']` (`Map`)::
Use this `Map` to add values for processing in a combine script.
Additional values must be of the type `Map`, `List`, `String` or
primitive. If an initialization script is provided as part the
aggregation then values added from the initialization script are
available as well. If no combine script is specified, values must be
directly stored in `_agg`. If no combine script and no
<<painless-metric-agg-reduce-context, reduce script>> are specified, the
values are used as the result.

*Return*

`void`::
No expected return value.

*API*

The standard <<painless-api-reference, Painless API>> is available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[[painless-metric-agg-reduce-context]]
=== Metric aggregation reduce context

Use a Painless script to
{es_version}/search-aggregations-metrics-scripted-metric-aggregation.html[reduce]
values to produce the result of a scripted metric aggregation. A reduce script
is run once on the coordinating node following a
<<painless-metric-agg-combine-context, combine script>> (or a
<<painless-metric-agg-map-context, map script>> if no combine script is
specified) and is optional as part of a full metric aggregation.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`params['_aggs']` (`Map`)::
`Map` with values available from the prior combine script (or a map
script if no combine script is specified).

*Return*

`List`, `Map`, `String`, or primitive::
A value used as the result.

*API*

The standard <<painless-api-reference, Painless API>> is available.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[[painless-min-should-match-context]]
=== Minimum should match context

Use a Painless script to specify the
{es_version}/query-dsl-terms-set-query.html[minimum] number of terms that a
specified field needs to match with for a document to be part of the query
results.

*Variables*

`params` (`Map`, read-only)::
User-defined parameters passed in as part of the query.

`params['num_terms']` (`int`, read-only)::
The number of terms specified to match with.

`doc` (`Map`, read-only)::
Contains the fields of the current document where each field is a
`List` of values.

*Return*

`int`::
The minimum number of terms required to match the current document.

*API*

The standard <<painless-api-reference, Painless API>> is available.
Loading