---
type: api
title: Render a search template
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-render-search-template
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-render-search-template
products:
  - Elasticsearch
---

# Render a search template


Availability:

## Paths

- `POST` (also `GET`) `/_render/template/{id}`
- `POST` (also `GET`) `/_render/template`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#bearerauth)

#### Path Parameters

- `id` (string Id) — optional, leave it out to use `/_render/template`
  The ID of the search template to render.
If no `source` is specified, this or the `id` request body parameter is required.

## Description

Render a search template as a search request body.

## Required authorization

* Index privileges: `read`

## Request Body

`application/json`

- `id` (string Id) — optional
  The 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>`.
- `file` (string) — optional
- `params` (map string to object) — optional
  Key-value pairs used to replace Mustache variables in the template.
The key is the variable name.
The value is the variable value.
- `source` (ScriptSource) — optional
  An inline search template.
It supports the same parameters as the search API's request body.
These parameters also support Mustache variables.
If no `id` or `<templated-id>` is specified, this parameter is required.

## Response

`application/json`

- `template_output` (map string to object)
## Code Examples

#### Console

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

#### JavaScript

```javascript
const response = await client.renderSearchTemplate({
  id: "my-search-template",
  params: {
    query_string: "hello world",
    from: 20,
    size: 10,
  },
});
```

#### Python

```python
resp = client.render_search_template(
    id="my-search-template",
    params={
        "query_string": "hello world",
        "from": 20,
        "size": 10
    },
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_render/template" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "my-search-template",
    "params": {
      "query_string": "hello world",
      "from": 20,
      "size": 10
    }
  }'
```

#### Java

```java
client.renderSearchTemplate(r -> r
    .id("my-search-template")
    .params(Map.of("size", JsonData.fromJson("10"),"from", JsonData.fromJson("20"),"query_string", JsonData.fromJson("\"hello world\"")))
);
```

#### C#

```c#
var response = await client
    .RenderSearchTemplateAsync(d1 => d1
        .Id("my-search-template")
        .Params(new Dictionary<string, object>()
        {
            { "query_string", "hello world" },
            { "from", 20 },
            { "size", 10 }
        })
    );
```

#### PHP

```php
$resp = $client->renderSearchTemplate([
    "body" => [
        "id" => "my-search-template",
        "params" => [
            "query_string" => "hello world",
            "from" => 20,
            "size" => 10,
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.render_search_template(
  body: {
    "id": "my-search-template",
    "params": {
      "query_string": "hello world",
      "from": 20,
      "size": 10
    }
  }
)
```

