script.asciidoc 2.6 KB

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