render-search-template-api.asciidoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. [[render-search-template-api]]
  2. === Render search template API
  3. ++++
  4. <titleabbrev>Render search template</titleabbrev>
  5. ++++
  6. Renders a <<search-template,search
  7. template>> as a <<search-search,search request body>>.
  8. ////
  9. [source,console]
  10. ----
  11. PUT _scripts/my-search-template
  12. {
  13. "script": {
  14. "lang": "mustache",
  15. "source": {
  16. "query": {
  17. "match": {
  18. "message": "{{query_string}}"
  19. }
  20. },
  21. "from": "{{from}}",
  22. "size": "{{size}}"
  23. },
  24. "params": {
  25. "query_string": "My query string"
  26. }
  27. }
  28. }
  29. ----
  30. // TESTSETUP
  31. ////
  32. [source,console]
  33. ----
  34. POST _render/template
  35. {
  36. "id": "my-search-template",
  37. "params": {
  38. "query_string": "hello world",
  39. "from": 20,
  40. "size": 10
  41. }
  42. }
  43. ----
  44. [[render-search-template-api-request]]
  45. ==== {api-request-title}
  46. `GET _render/template`
  47. `GET _render/template/<template-id>`
  48. `POST _render/template`
  49. `POST _render/template/<template-id>`
  50. [[render-search-template-api-prereqs]]
  51. ==== {api-prereq-title}
  52. * If the {es} {security-features} are enabled, you must have the `read`
  53. <<privileges-list-indices,index privilege>> for at least one index pattern.
  54. [[render-search-template-api-path-params]]
  55. ==== {api-path-parms-title}
  56. `<template-id>`::
  57. (Required*, string) ID of the search template to render. If no `source` is
  58. specified, this or the `id` request body parameter is required.
  59. [[render-search-template-api-request-body]]
  60. ==== {api-request-body-title}
  61. `id`::
  62. (Required*, string) ID of the search template to render. If no `source` is
  63. specified, this or the `<template-id>` request path parameter is required. If
  64. you specify both this parameter and the `<template-id>` parameter, the API uses
  65. only `<template-id>`.
  66. `params`::
  67. (Optional, object) Key-value pairs used to replace Mustache variables in the
  68. template. The key is the variable name. The value is the variable value.
  69. `source`::
  70. (Required*, object) An inline search template. Supports the same parameters as
  71. the <<search-search,search API>>'s request body. These parameters also support
  72. https://mustache.github.io/[Mustache] variables. If no `id` or `<templated-id>`
  73. is specified, this parameter is required.