컴포넌트 템플릿 API (Component template APIs)
1.0에서 도입
component template APIs를 사용해 컴포넌트 템플릿을 생성, 조회, 업데이트, 삭제할 수 있습니다. 컴포넌트 템플릿은 설정, 매핑, 별칭을 정의하고 여러 인덱스 템플릿에 걸쳐 공유할 수 있는 재사용 가능한 구성 요소입니다.
인덱스 템플릿은 여러 컴포넌트 템플릿으로 구성될 수 있습니다. 컴포넌트 템플릿을 인덱스 템플릿에 통합하려면 인덱스 템플릿의 composed_of 섹션에 그 컴포넌트 템플릿을 나열해야 합니다. 컴포넌트 템플릿은 인덱스 템플릿에 지정된 기준과 일치하는 새로 생성되는 데이터 스트림과 인덱스에만 적용됩니다.
인덱스 템플릿이나 인덱스 생성 요청에 설정이나 매핑이 직접 정의되어 있다면, 그 설정이 컴포넌트 템플릿에 지정된 설정이나 매핑보다 우선합니다.
컴포넌트 템플릿은 인덱스 생성 과정에서만 사용됩니다. 데이터 스트림의 경우 여기에는 데이터 스트림 자체의 생성과 스트림을 뒷받침하는 backing index의 생성이 포함됩니다. 컴포넌트 템플릿에 대한 수정은 데이터 스트림의 backing index를 포함해 기존 인덱스에 영향을 주지 않습니다.
출처: OpenSearch 문서
본문
Endpoints
PUT _component_template/{component-template-name}
GET _component_template/{component-template-name}
DELETE _component_template/{component-template-name}
HEAD _component_template/{component-template-name}
- PUT: 컴포넌트 템플릿을 생성하거나 업데이트합니다. query 매개변수와 요청 본문을 모두 받습니다.
- GET: 기존 컴포넌트 템플릿에 대한 정보를 검색합니다. query 매개변수만 받습니다.
- DELETE: 기존 컴포넌트 템플릿을 삭제합니다. query 매개변수만 받습니다.
- HEAD: 컴포넌트 템플릿이 존재하는지 여부를 반환합니다. HTTP 상태 코드만 반환합니다.
Path parameters
다음 표는 사용 가능한 path 매개변수를 나열한 것입니다.
| Parameter | Data type | Description | | component-template-name | String | 컴포넌트 템플릿의 이름입니다. PUT, HEAD, DELETE 연산에는 필수이고 GET 연산에는 선택 사항입니다. |
Query parameters
다음 표는 사용 가능한 query 매개변수를 나열한 것입니다. 모든 query 매개변수는 선택 사항입니다.
| Parameter | Data type | Description | Supported operations | | create | Boolean | true 일 때 API는 기존 컴포넌트 템플릿을 교체하거나 업데이트할 수 없습니다. 기본값은 false 입니다. | PUT | | cluster_manager_timeout | Time | 클러스터 매니저 노드에 대한 연결을 기다리는 시간입니다. 기본값은 30s 입니다. | PUT, GET, DELETE |
Create or update a component template
PUT 연산을 사용해 새 컴포넌트 템플릿을 생성하거나 기존 것을 업데이트합니다.
Endpoints
PUT _component_template/{component-template-name}
Request body fields
다음 표는 사용 가능한 요청 본문 필드를 나열한 것입니다.
| Parameter | Data type | Description | | template | Object | 인덱스에 대한 별칭, 매핑, 설정을 포함하는 템플릿입니다. 자세한 내용은 [#template]을 참고하세요. 필수입니다. | | version | Integer | 인덱스 템플릿 관리를 위해 사용하는 버전 번호입니다. 버전 번호는 OpenSearch가 자동으로 설정하지 않습니다. 선택 사항입니다. | | _meta | Object | 인덱스 템플릿에 대한 세부 정보를 제공하는 메타데이터입니다. 선택 사항입니다. | | allow_auto_create | Boolean | true 일 때 actions.auto_create_index 가 비활성화되어 있어도 이 템플릿으로 인덱스를 자동 생성할 수 있습니다. false 일 때 템플릿과 일치하는 인덱스와 데이터 스트림은 자동으로 생성될 수 없습니다. 선택 사항입니다. | | deprecated | Boolean | true 일 때 컴포넌트 템플릿은 더 이상 사용되지 않습니다(deprecated). deprecated 이면 템플릿이 참조될 때마다 OpenSearch가 경고를 출력합니다. |
Template
요청 본문의 template 옵션과 함께 다음 객체를 사용할 수 있습니다.
alias
템플릿과 연결할 별칭의 이름을 키로 지정합니다. 요청 본문에 template 옵션이 존재할 때 필수입니다. 이 옵션은 여러 별칭을 지원합니다.
객체 본문에는 다음 선택적 별칭 매개변수가 포함됩니다.
| Parameter | Data type | Description | | filter | Query DSL object | 별칭이 접근할 수 있는 문서 수를 제한하는 쿼리입니다. | | index_routing | String | 인덱싱 연산을 특정 샤드로 라우팅하는 값입니다. 지정하면 인덱싱 연산의 라우팅 값을 덮어씁니다. | | is_hidden | Boolean | true 일 때 별칭은 숨겨집니다. 기본값은 false 입니다. 모든 별칭 인덱스는 이 설정에 대해 일치하는 값을 가져야 합니다. | | is_write_index | Boolean | true 일 때 해당 인덱스는 별칭의 쓰기 인덱스입니다. 기본값은 false 입니다. | | routing | String | 인덱스 및 검색 연산을 특정 샤드로 라우팅하는 데 사용하는 값입니다. | | search_routing | String | 검색 연산을 특정 샤드에 쓰기 위해 사용하는 값입니다. 지정하면 검색 연산의 라우팅 값을 덮어씁니다. |
mappings
인덱스에 존재하는 필드 매핑입니다. 자세한 내용은 Mappings and field types를 참고하세요. 선택 사항입니다.
settings
인덱스에 대한 구성 옵션입니다. 자세한 내용은 Index settings를 참고하세요.
Example request: Create a component template with index aliases
다음 예제 요청은 인덱스 별칭을 포함한 컴포넌트 템플릿을 생성합니다.
REST Python
PUT /_component_template/alias_template
{
"template": {
"settings": {
"number_of_shards": 1
},
"aliases": {
"alias1": {},
"alias2": {
"filter": {
"term": {
"user.id": "hamlet"
}
},
"routing": "shard-1"
},
"{index}-alias": {}
}
}
}
Copy Copy as cURL
response = client.cluster.put_component_template(
name = "alias_template",
body = {
"template": {
"settings": {
"number_of_shards": 1
},
"aliases": {
"alias1": {},
"alias2": {
"filter": {
"term": {
"user.id": "hamlet"
}
},
"routing": "shard-1"
},
"{index}-alias": {}
}
}
}
)
Copy
Example request: Add component versioning
다음 예제는 컴포넌트 템플릿에 버전 번호를 추가합니다. 이는 외부 시스템에서 템플릿 관리를 단순화해 줍니다.
REST Python
PUT /_component_template/version_template
{
"template": {
"settings": {
"number_of_shards": 1
}
},
"version": 3
}
Copy Copy as cURL
response = client.cluster.put_component_template(
name = "version_template",
body = {
"template": {
"settings": {
"number_of_shards": 1
}
},
"version": 3
}
)
Copy
Example request: Add template metadata
다음 예제 요청은 _meta 매개변수를 사용해 컴포넌트 템플릿에 메타데이터를 추가합니다. 모든 메타데이터는 클러스터 상태에 저장됩니다.
REST Python
PUT /_component_template/meta_template
{
"template": {
"settings": {
"number_of_shards": 1
}
},
"_meta": {
"description": "Where art thou",
"serialization": {
"class": "MyIndexTemplate",
"id": 12
}
}
}
Copy Copy as cURL
response = client.cluster.put_component_template(
name = "meta_template",
body = {
"template": {
"settings": {
"number_of_shards": 1
}
},
"_meta": {
"description": "Where art thou",
"serialization": {
"class": "MyIndexTemplate",
"id": 12
}
}
}
)
Copy
Retrieve component template
GET 연산을 사용해 하나 또는 여러 컴포넌트 템플릿과 그 정보를 검색합니다.
Endpoints
GET /_component_template/{component-template-name}
GET /_component_template
Path parameters
다음 표는 사용 가능한 path 매개변수를 나열한 것입니다. 모든 path 매개변수는 선택 사항입니다.
| Parameter | Data type | Description | | component-template-name | String | 검색할 컴포넌트 템플릿의 이름입니다. 와일드카드 표현식(*)을 지원합니다. 지정하지 않으면 모든 컴포넌트 템플릿이 반환됩니다. |
Example request: Retrieve a component template by name
REST Python
GET /_component_template/my_template
Copy Copy as cURL
response = client.cluster.get_component_template(
name = "my_template"
)
Copy
Example request: Retrieve component templates using a wildcard pattern
REST Python
GET /_component_template/my_template*
Copy Copy as cURL
response = client.cluster.get_component_template(
name = "my_template*"
)
Copy
Example request: Retrieve all component templates
REST Python
GET /_component_template
Copy Copy as cURL
response = client.cluster.get_component_template()
Copy
Delete component template
DELETE 연산을 사용해 클러스터에서 컴포넌트 템플릿을 제거합니다.
중요 고려 사항:
- 컴포넌트 템플릿을 삭제해도 그 템플릿을 사용해 생성된 기존 인덱스에는 영향을 주지 않습니다.
- 현재 인덱스 템플릿이 참조하고 있는 컴포넌트 템플릿은 삭제할 수 없습니다.
- 이 연산은 되돌릴 수 없습니다.
Endpoints
DELETE _component_template/{component-template-name}
Example request
REST Python
DELETE /_component_template/my_template
Copy Copy as cURL
response = client.cluster.delete_component_template(
name = "my_template"
)
Copy
Check whether a component template exists
HEAD 연산을 사용해 컴포넌트 템플릿 내용을 가져오지 않고 존재 여부만 확인합니다. 이 연산은 응답 본문 없이 HTTP 상태 코드와 헤더만 반환합니다.
Endpoints
HEAD _component_template/{component-template-name}
Example request
REST Python
HEAD /_component_template/my_template
Copy Copy as cURL
response = client.cluster.exists_component_template(
name = "my_template"
)
Copy
Response codes
- 200: 컴포넌트 템플릿이 존재합니다.
- 404: 컴포넌트 템플릿이 존재하지 않습니다.
Required permissions
Security 플러그인을 사용한다면 적절한 권한이 있는지 확인하세요. 이 API에 필요한 권한은 다음과 같습니다.
- cluster:admin/component_template/get: 컴포넌트 템플릿 가져오기에 필요
- cluster:admin/component_template/put: 컴포넌트 템플릿 생성 또는 업데이트에 필요
- cluster:admin/component_template/delete: 컴포넌트 템플릿 삭제에 필요