Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Render Template API #7219

Merged
merged 6 commits into from
Jul 1, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions _api-reference/render-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
layout: default
title: Render Template
nav_order: 82
---

# Render Template

Check failure on line 7 in _api-reference/render-template.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _api-reference/render-template.md#L7

[OpenSearch.HeadingCapitalization] 'Render Template' is a heading and should be in sentence case.
Raw output
{"message": "[OpenSearch.HeadingCapitalization] 'Render Template' is a heading and should be in sentence case.", "location": {"path": "_api-reference/render-template.md", "range": {"start": {"line": 7, "column": 3}}}, "severity": "ERROR"}

The Render Template API renders a [search template]({{site.url}}{{site.baseurl}}/search-plugins/search-template/) as a search query.

## Paths and HTTP methods

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

## Path parameters

The Render Template API supports the following path parameter. All path parameters are optional.
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved

| Parameter | Type | Description |
| :--- | :--- | :--- |
| `id` | String | The ID of search template to render. |
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved

## Request options

The following options are supported in the request body of the Render Template API.

| Parameter | Required | 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 which replace Mustache variables found in the search template. The key value pairs must exist inside the documents being searched. |
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved
| `source` | Conditional | Object | An inline search template to render if a search template is not specified. Supports the same parameters as a [Search]({{site.url}}{{site.baseurl}}/api-reference/search/) API request, as well as [Mustache](https://mustache.github.io/mustache.5.html) variables. |
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved

## Example request
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved

The following example requests validates a search template with the ID `play_search_template`:
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved

```json
POST _render/template
{
"id": "play_search_template",
"params": {
"play_name": "Henry IV"
}
}
```
{% include copy.html %}

## Example response

OpenSearch responds with information about the templates output:
Naarcha-AWS marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"template_output": {
"from": "0",
"size": "10",
"query": {
"match": {
"play_name": "Henry IV"
}
}
}
}
```




Loading