2019-09-10 13:32:51 -04:00
|
|
|
[role="xpack"]
|
2017-03-28 17:23:01 -04:00
|
|
|
[[transform-script]]
|
2019-11-20 19:41:58 -05:00
|
|
|
=== Script {watcher-transform}
|
2017-03-28 17:23:01 -04:00
|
|
|
|
2019-11-20 19:41:58 -05:00
|
|
|
A <<transform,{watcher-transform}>> that executes a script on the current
|
|
|
|
payload in the watch execution context and replaces it with a newly generated
|
|
|
|
one. The following snippet shows how a simple script {watcher-transform} can be
|
|
|
|
defined on the watch level:
|
2017-03-28 17:23:01 -04:00
|
|
|
|
2019-11-20 19:41:58 -05:00
|
|
|
TIP: The `script` {watcher-transform} is often useful when used in combination
|
|
|
|
with the <<transform-search,`search`>> {watcher-transform}, where the
|
|
|
|
script can extract only the significant data from a search result, and by
|
|
|
|
that, keep the payload minimal. This can be achieved with the
|
|
|
|
<<transform-chain,`chain`>> {watcher-transform}.
|
2017-03-28 17:23:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"transform" : {
|
|
|
|
"script" : "return [ 'time' : ctx.trigger.scheduled_time ]" <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2018-06-22 21:09:37 -04:00
|
|
|
// NOTCONSOLE
|
2017-03-28 17:23:01 -04:00
|
|
|
<1> A simple `painless` script that creates a new payload with a single `time`
|
|
|
|
field holding the scheduled time.
|
|
|
|
|
|
|
|
NOTE: The executed script may either return a valid model that is the equivalent
|
|
|
|
of a Java(TM) Map or a JSON object (you will need to consult the
|
|
|
|
documentation of the specific scripting language to find out what this
|
|
|
|
construct is). Any other value that is returned will be assigned and
|
|
|
|
accessible to/via the `_value` variable.
|
|
|
|
|
|
|
|
The `script` attribute may hold a string value in which case it will be treated
|
|
|
|
as an inline script and the default elasticsearch script languages will be assumed
|
2019-09-30 13:18:50 -04:00
|
|
|
(as described in <<modules-scripting>>). You can
|
2017-03-28 17:23:01 -04:00
|
|
|
use the other scripting languages supported by Elasticsearch. For this, you need
|
|
|
|
to set the `script` field to an object describing the script and its language.
|
|
|
|
The following table lists the possible settings that can be configured:
|
|
|
|
|
|
|
|
[[transform-script-settings]]
|
2019-11-20 19:41:58 -05:00
|
|
|
.Script {watcher-transform} settings
|
2019-02-27 18:33:50 -05:00
|
|
|
[options="header"]
|
2017-03-28 17:23:01 -04:00
|
|
|
|======
|
|
|
|
| Name |Required | Default | Description
|
|
|
|
|
2019-02-27 18:33:50 -05:00
|
|
|
| `inline` | yes | - | When using an inline script, this field holds
|
2017-03-28 17:23:01 -04:00
|
|
|
the script itself.
|
|
|
|
|
2019-02-27 18:33:50 -05:00
|
|
|
| `id` | yes | - | When referring to a stored script, this
|
2017-03-28 17:23:01 -04:00
|
|
|
field holds the id of the script.
|
|
|
|
|
|
|
|
| `lang` | no | `painless` | The script language
|
|
|
|
|
|
|
|
| `params` | no | - | Additional parameters/variables that are
|
|
|
|
accessible by the script
|
|
|
|
|======
|
|
|
|
|
|
|
|
When using the object notation of the script, one (and only one) of `inline`,
|
2019-02-27 18:33:50 -05:00
|
|
|
or `id` fields must be defined.
|
2017-03-28 17:23:01 -04:00
|
|
|
|
|
|
|
NOTE: In addition to the provided `params`, the scripts also have access to the
|
2019-09-30 13:18:50 -04:00
|
|
|
<<watch-execution-context,standard watch execution context parameters>>.
|
2017-03-28 17:23:01 -04:00
|
|
|
|