Skip to content

Commit

Permalink
[7.13] [DOCS] Ingest methods for Painless (#72722) (#74759)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann committed Jun 30, 2021
1 parent 2563d2e commit 79e6c08
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/painless/painless-guide/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ include::painless-method-dispatch.asciidoc[]

include::painless-debugging.asciidoc[]

include::painless-execute-script.asciidoc[]
include::painless-execute-script.asciidoc[]

include::painless-ingest.asciidoc[]
98 changes: 98 additions & 0 deletions docs/painless/painless-guide/painless-ingest.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[[painless-ingest]]
=== Using ingest processors in Painless

Some {ref}/processors.html[ingest processors] expose behavior through Painless
methods that can be called in Painless scripts that execute in ingest pipelines.

==== Method usage

All ingest methods available in Painless are scoped to the `Processors`
namespace. For example:

[source,console]
----
POST /_ingest/pipeline/_simulate?verbose
{
"pipeline": {
"processors": [
{
"script": {
"lang": "painless",
"source": """
long bytes = Processors.bytes(ctx.size);
ctx.size_in_bytes = bytes;
"""
}
}
]
},
"docs": [
{
"_source": {
"size": "1kb"
}
}
]
}
----

==== Ingest methods reference

===== Byte conversion
Use the {ref}/bytes-processor.html[bytes processor] to return the number of
bytes in the human-readable byte value supplied in the `value` parameter.

[source,Painless]
----
long bytes(String value);
----

===== Lowercase conversion
Use the {ref}/lowercase-processor.html[lowercase processor] to convert the
supplied string in the `value` parameter to its lowercase equivalent.

[source,Painless]
----
String lowercase(String value);
----

===== Uppercase conversion
Use the {ref}/uppercase-processor.html[uppercase processor] to convert the
supplied string in the `value` parameter to its uppercase equivalent.

[source,Painless]
----
String uppercase(String value);
----

===== JSON parsing
Use the {ref}/json-processor.html[JSON processor] to convert JSON strings to structured
JSON objects. The first `json` method accepts a map and a key. The processor converts
the JSON string in the map as specified by the `key` parameter to structured JSON content.
That content is added directly to the `map` object.

The second `json` method accepts a JSON string in the `value` parameter and
returns a structured JSON object.

[source,Painless]
----
void json(Map<String, Object> map, String key);
Object json(Object value);
----

You can then add this object to the document through the context object:

[source,Painless]
----
Object json = Processors.json(ctx.inputJsonString);
ctx.structuredJson = json;
----

===== URL decoding
Use the {ref}/urldecode-processor.html[URL decode processor] to URL-decode the string
supplied in the `value` parameter.

[source,Painless]
----
String urlDecode(String value);
----

0 comments on commit 79e6c08

Please sign in to comment.