diff --git a/explore-analyze/scripting/script-fields-api.md b/explore-analyze/scripting/script-fields-api.md index 877e4308eb..33a692099c 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', ) +``` + 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: ```painless @@ -77,7 +83,6 @@ ZonedDateTime end = field('end').get(null); return start == null || end == null ? -1 : ChronoUnit.MILLIS.between(start, end) ``` - ## Supported mapped field types [_supported_mapped_field_types] The following table indicates the mapped field types that the `field` API supports. For each supported type, values are listed that are returned by the `field` API (from the `get` and `as` 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" + } +} +```