[[render-search-template-api]]
=== Render search template API
++++
<titleabbrev>Render search template</titleabbrev>
++++

Renders a <<search-template,search
template>> as a <<search-search,search request body>>.

////
[source,console]
----
PUT _scripts/my-search-template
{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "match": {
          "message": "{{query_string}}"
        }
      },
      "from": "{{from}}",
      "size": "{{size}}"
    },
    "params": {
      "query_string": "My query string"
    }
  }
}
----
// TESTSETUP
////

[source,console]
----
POST _render/template
{
  "id": "my-search-template",
  "params": {
    "query_string": "hello world",
    "from": 20,
    "size": 10
  }
}
----

[[render-search-template-api-request]]
==== {api-request-title}

`GET _render/template`

`GET _render/template/<template-id>`

`POST _render/template`

`POST _render/template/<template-id>`

[[render-search-template-api-prereqs]]
==== {api-prereq-title}

* If the {es} {security-features} are enabled, you must have the `read`
<<privileges-list-indices,index privilege>> for at least one index pattern.

[[render-search-template-api-path-params]]
==== {api-path-parms-title}

`<template-id>`::
(Required*, string) ID of the search template to render. If no `source` is
specified, this or the `id` request body parameter is required.

[[render-search-template-api-request-body]]
==== {api-request-body-title}

`id`::
(Required*, string) ID of the search template to render. If no `source` is
specified, this or the `<template-id>` request path parameter is required. If
you specify both this parameter and the `<template-id>` parameter, the API uses
only `<template-id>`.

`params`::
(Optional, object) Key-value pairs used to replace Mustache variables in the
template. The key is the variable name. The value is the variable value.

`source`::
(Required*, object) An inline search template. Supports the same parameters as
the <<search-search,search API>>'s request body. These parameters also support
https://mustache.github.io/[Mustache] variables. If no `id` or `<templated-id>`
is specified, this parameter is required.
