scripting.asciidoc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. === Scripting changes
  2. ==== Scripting syntax
  3. The syntax for scripts has been made consistent across all APIs. The accepted
  4. format is as follows:
  5. Inline/Dynamic scripts::
  6. +
  7. --
  8. [source,js]
  9. ---------------
  10. "script": {
  11. "inline": "doc['foo'].value + val", <1>
  12. "lang": "groovy", <2>
  13. "params": { "val": 3 } <3>
  14. }
  15. ---------------
  16. <1> The inline script to execute.
  17. <2> The optional language of the script.
  18. <3> Any named parameters.
  19. --
  20. Indexed scripts::
  21. +
  22. --
  23. [source,js]
  24. ---------------
  25. "script": {
  26. "id": "my_script_id", <1>
  27. "lang": "groovy", <2>
  28. "params": { "val": 3 } <3>
  29. }
  30. ---------------
  31. <1> The ID of the indexed script.
  32. <2> The optional language of the script.
  33. <3> Any named parameters.
  34. --
  35. File scripts::
  36. +
  37. --
  38. [source,js]
  39. ---------------
  40. "script": {
  41. "file": "my_file", <1>
  42. "lang": "groovy", <2>
  43. "params": { "val": 3 } <3>
  44. }
  45. ---------------
  46. <1> The filename of the script, without the `.lang` suffix.
  47. <2> The optional language of the script.
  48. <3> Any named parameters.
  49. --
  50. For example, an update request might look like this:
  51. [source,js]
  52. ---------------
  53. POST my_index/my_type/1/_update
  54. {
  55. "script": {
  56. "inline": "ctx._source.count += val",
  57. "params": { "val": 3 }
  58. },
  59. "upsert": {
  60. "count": 0
  61. }
  62. }
  63. ---------------
  64. A short syntax exists for running inline scripts in the default scripting
  65. language without any parameters:
  66. [source,js]
  67. ----------------
  68. GET _search
  69. {
  70. "script_fields": {
  71. "concat_fields": {
  72. "script": "doc['one'].value + ' ' + doc['two'].value"
  73. }
  74. }
  75. }
  76. ----------------
  77. ==== Scripting settings
  78. The `script.disable_dynamic` node setting has been replaced by fine-grained
  79. script settings described in <<migration-script-settings>>.
  80. ==== Groovy scripts sandbox
  81. The Groovy sandbox and related settings have been removed. Groovy is now a
  82. non-sandboxed scripting language, without any option to turn the sandbox on.
  83. ==== Plugins making use of scripts
  84. Plugins that make use of scripts must register their own script context
  85. through `ScriptModule`. Script contexts can be used as part of fine-grained
  86. settings to enable/disable scripts selectively.