From a781623b7196af0607123880397b189be9489a99 Mon Sep 17 00:00:00 2001 From: Philipp Kahr Date: Tue, 22 Jul 2025 14:23:13 +0200 Subject: [PATCH 1/2] Update script-fields-api.md Add the MUCH needed example of using the `set` call to manipulate field data. --- .../scripting/script-fields-api.md | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/explore-analyze/scripting/script-fields-api.md b/explore-analyze/scripting/script-fields-api.md index 877e4308eb..8685a8d3e6 100644 --- a/explore-analyze/scripting/script-fields-api.md +++ b/explore-analyze/scripting/script-fields-api.md @@ -25,6 +25,12 @@ Use the `field` API to access document fields: field('my_field').get() ``` +Alternatively use the shortcut of `$` to get a field. + +```painless +$('my_field', ` methods) and the `doc` map (from the `getValue` and `get` methods). @@ -112,3 +117,20 @@ The `fields` API currently doesn’t support some fields, but you can still acce | `wildcard` | `String` | - | `String` | `String` | | `flattened` | `String` | - | `String` | `String` | +## Manipulation of the fields data + +The field API provides a `set()` operation that will take the field name and create the necessary structure. Calling this inside an ingest pipelines script processor context: + +```painless +field("foo.bar").set("abc") +``` + +leads to the generation of this JSON representation. + +```json +{ + "foo": { + "bar": "abc" + } +} +``` From 0d2e4266b45878645ed5fb387eaf80f4131c6b13 Mon Sep 17 00:00:00 2001 From: Philipp Kahr Date: Tue, 22 Jul 2025 15:08:02 +0200 Subject: [PATCH 2/2] Update explore-analyze/scripting/script-fields-api.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: István Zoltán Szabó --- explore-analyze/scripting/script-fields-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/explore-analyze/scripting/script-fields-api.md b/explore-analyze/scripting/script-fields-api.md index 8685a8d3e6..33a692099c 100644 --- a/explore-analyze/scripting/script-fields-api.md +++ b/explore-analyze/scripting/script-fields-api.md @@ -28,7 +28,7 @@ field('my_field').get() Alternatively use the shortcut of `$` to get a field. ```painless -$('my_field', ) ``` This API fundamentally changes how you access documents in Painless. Previously, you had to access the `doc` map with the field name that you wanted to access: