You're viewing version 3.1 of the OpenSearch documentation. This version is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.
Render Template API
The Render Template API previews the final query generated from a search template by substituting parameters without executing the search.
Endpoints
GET /_render/template
POST /_render/template
GET /_render/template/<id>
POST /_render/template/<id>
Path parameters
The following table lists the available path parameters. All path parameters are optional.
Parameter | Data type | Description |
---|---|---|
id | String | The ID of the search template to render. |
Request body fields
The following table lists the available request body fields.
Parameter | Required | Data type | Description |
---|---|---|---|
id | Conditional | String | The ID of the search template to render. Is not required if the ID is provided in the path or if an inline template is specified by the source . |
params | No | Object | A list of key-value pairs that replace Mustache variables found in the search template. The key-value pairs must exist in the documents being searched. |
source | Conditional | Object | An inline search template to render if a search template is not specified. Supports the same parameters as a Search API request and Mustache variables. |
Example request
Both of the following request examples use the search template with the template ID play_search_template
:
{
"source": {
"query": {
"match": {
"play_name": "{{play_name}}"
}
}
},
"params": {
"play_name": "Henry IV"
}
}
Render template using template ID
The following example request validates a search template with the ID play_search_template
:
POST _render/template
{
"id": "play_search_template",
"params": {
"play_name": "Henry IV"
}
}
Render template using _source
If you don’t want to use a saved template, or want to test a template before saving, you can test a template with the _source
parameter using Mustache variables, as shown in the following example:
{
"source": {
"from": "{{from}}{{^from}}0{{/from}}",
"size": "{{size}}{{^size}}10{{/size}}",
"query": {
"match": {
"play_name": "{{play_name}}"
}
}
},
"params": {
"play_name": "Henry IV"
}
}
Example response
OpenSearch responds with information about the template’s output:
{
"template_output": {
"from": "0",
"size": "10",
"query": {
"match": {
"play_name": "Henry IV"
}
}
}
}