본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Render Template API

원문 보기 위키 갱신

Render Template API는 검색 템플릿(search template)에서 생성된 최종 쿼리를, 검색을 실제로 실행하지 않고 매개변수를 대입해 미리 보여주는 API예요. 템플릿이 어떻게 렌더링될지 먼저 확인하고 싶을 때 유용해요. 이 기능은 OpenSearch 1.0에서 처음 소개되었어요.

출처: OpenSearch 문서

본문

엔드포인트

GET /_render/template
POST /_render/template
GET /_render/template/{id}
POST /_render/template/{id}

경로 매개변수

다음 표는 사용 가능한 경로 매개변수 목록이에요. 모든 경로 매개변수는 선택 사항이에요.

| Parameter | Data type | Description | | id | String | The ID of the search template to render. |

요청 본문 필드

다음 표는 사용 가능한 요청 본문 필드를 보여줘요.

| 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. |

예제 요청

다음 두 요청 예제는 모두 검색 템플릿 ID가 play_search_template인 템플릿을 사용해요:

{
"source": {
"query": {
"match": {
"play_name": "{{play_name}}"
}
}
},
"params": {
"play_name": "Henry IV"
}
}

템플릿 ID로 템플릿 렌더링

다음 예제 요청은 ID가 play_search_template인 검색 템플릿을 검증해요:

POST /_render/template
{
"id": "play_search_template",
"params": {
"play_name": "Henry IV"
}
}
response = client.render_search_template(
body =   {
"id": "play_search_template",
"params": {
"play_name": "Henry IV"
}
}
)

_source로 템플릿 렌더링

저장된 템플릿을 사용하고 싶지 않거나, 저장하기 전에 템플릿을 테스트하고 싶다면 다음 예제처럼 Mustache 변수를 사용해 _source 매개변수로 템플릿을 테스트할 수 있어요:

{
"source": {
"from": "{{from}}{{^from}}0{{/from}}",
"size": "{{size}}{{^size}}10{{/size}}",
"query": {
"match": {
"play_name": "{{play_name}}"
}
}
},
"params": {
"play_name": "Henry IV"
}
}

예제 응답

OpenSearch는 템플릿의 출력에 대한 정보로 응답해요:

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

더 알아보기 (Learn more)

검색 템플릿을 더 유연하게 활용하고 싶다면 원문 OpenSearch 문서를 확인해 주세요.