scripting.asciidoc 2.1 KB

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