create-stored-script-api.asciidoc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. [[create-stored-script-api]]
  2. === Create or update stored script API
  3. ++++
  4. <titleabbrev>Create or update stored script</titleabbrev>
  5. ++++
  6. Creates or updates a <<script-stored-scripts,stored script>> or
  7. <<search-template,search template>>.
  8. [source,console]
  9. ----
  10. PUT _scripts/my-stored-script
  11. {
  12. "script": {
  13. "lang": "painless",
  14. "source": "Math.log(_score * 2) + params['my_modifier']"
  15. }
  16. }
  17. ----
  18. ////
  19. [source,console]
  20. ----
  21. DELETE _scripts/my-stored-script
  22. ----
  23. // TEST[continued]
  24. ////
  25. [[create-stored-script-api-request]]
  26. ==== {api-request-title}
  27. `PUT _scripts/<script-id>`
  28. `POST _scripts/<script-id>`
  29. `PUT _scripts/<script-id>/<context>`
  30. `POST _scripts/<script-id>/<context>`
  31. [[create-stored-script-api-prereqs]]
  32. ==== {api-prereq-title}
  33. * If the {es} {security-features} are enabled, you must have the `manage`
  34. <<privileges-list-cluster,cluster privilege>> to use this API.
  35. [[create-stored-script-api-path-params]]
  36. ==== {api-path-parms-title}
  37. `<script-id>`::
  38. (Required, string)
  39. Identifier for the stored script or search template. Must be unique within the
  40. cluster.
  41. `<context>`::
  42. (Optional, string)
  43. Context in which the script or search template should run. To prevent errors,
  44. the API immediately compiles the script or template in this context.
  45. [[create-stored-script-api-query-params]]
  46. ==== {api-query-parms-title}
  47. `context`::
  48. (Optional, string)
  49. Context in which the script or search template should run. To prevent errors,
  50. the API immediately compiles the script or template in this context.
  51. +
  52. If you specify both this and the `<context>` request path parameter, the API
  53. uses the request path parameter.
  54. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  55. [role="child_attributes"]
  56. [[create-stored-script-api-request-body]]
  57. ==== {api-request-body-title}
  58. `script`::
  59. (Required, object)
  60. Contains the script or search template, its parameters, and its language.
  61. +
  62. .Properties of `script`
  63. [%collapsible%open]
  64. ====
  65. `lang`::
  66. (Required, string)
  67. <<scripting-available-languages,Script language>>. For search templates, use
  68. `mustache`.
  69. `source`::
  70. (Required, string or object)
  71. For scripts, a string containing the script.
  72. +
  73. For search templates, an object containing the search template. The object
  74. supports the same parameters as the <<search-search,search API>>'s request body.
  75. Also supports https://mustache.github.io/[Mustache] variables. See
  76. <<search-template>>.
  77. `params`::
  78. (Optional, object)
  79. Parameters for the script or search template.
  80. ====