-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2563d2e
commit 79e6c08
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
---- |