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

Simulate Index Templates API

원문 보기 위키 갱신

인덱스 템플릿이 인덱스에 어떻게 적용될지 미리 보거나, 인덱스 템플릿을 만들기 전에 시뮬레이션할 수 있는 API예요. OpenSearch 1.0에서 도입됐고요.

출처: OpenSearch 문서

본문

엔드포인트

POST /_index_template/_simulate
POST /_index_template/_simulate/{template_name}
POST /_index_template/_simulate_index/{index_name}

경로 매개변수

아래 표는 사용 가능한 경로 매개변수 목록이에요.

| Parameter | Data type | Description | | template_name | String | 시뮬레이션할 인덱스 템플릿의 이름. | | index_name | String | 템플릿 해석을 시뮬레이션하는 데 사용할 인덱스의 이름. |

요청 본문 필드

아래 표는 사용 가능한 요청 본문 필드 목록이에요.

| Field | Data type | Description | | index_patterns | Array | 템플릿이 적용되는 인덱스 패턴. | | template | Object | 템플릿 정의. | | template.settings | Object | 적용할 인덱스 설정. | | template.mappings | Object | 적용할 필드 매핑. | | template.aliases | Object | 적용할 별칭. | | priority | Integer | 템플릿의 우선순위 값. 여러 템플릿이 인덱스와 매칭될 때 어떤 템플릿이 적용될지 결정하는 데 사용. 값이 클수록 우선. | | version | Integer | 템플릿 버전. | | _meta | Object | 템플릿의 메타데이터. |

요청 예시: 템플릿 시뮬레이션

다음 요청을 사용해 템플릿을 만들지 않고 시뮬레이션할 수 있어요:

REST Python

POST /_index_template/_simulate_index/logs-sim-1

Copy Copy as cURL

response = client.indices.simulate_index_template(
name = "logs-sim-1",
body = { "Insert body here" }
)

Copy

요청 예시: 이름이 있는 템플릿 시뮬레이션

REST Python

POST /_index_template/_simulate/template_for_simulation

Copy Copy as cURL

response = client.indices.simulate_template(
name = "template_for_simulation",
body = { "Insert body here" }
)

Copy 템플릿의 이름을 지정하면 특정 템플릿을 시뮬레이션할 수 있어요.

먼저 다음 요청으로 template_for_simulation이라는 템플릿을 만드세요:

REST Python

PUT /_index_template/template_for_simulation
{
"index_patterns": [
"logs-sim-*"
],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"timestamp": {
"type": "date"
},
"message": {
"type": "text"
},
"level": {
"type": "keyword"
}
}
}
},
"priority": 10,
"version": 1,
"_meta": {
"description": "Template used for simulation example",
"owner": "Docs Team"
}
}

Copy Copy as cURL

response = client.indices.put_index_template(
name = "template_for_simulation",
body =   {
"index_patterns": [
"logs-sim-*"
],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"timestamp": {
"type": "date"
},
"message": {
"type": "text"
},
"level": {
"type": "keyword"
}
}
}
},
"priority": 10,
"version": 1,
"_meta": {
"description": "Template used for simulation example",
"owner": "Docs Team"
}
}
)

Copy 이제 template_for_simulation이라는 템플릿을 시뮬레이션할 수 있어요:

REST Python

POST /_index_template/_simulate/template_for_simulation

Copy Copy as cURL

response = client.indices.simulate_template(
name = "template_for_simulation",
body = { "Insert body here" }
)

Copy

요청 예시: 특정 인덱스에 템플릿 시뮬레이션

특정 인덱스 이름에 템플릿을 시뮬레이션하는 것은 템플릿 간 충돌을 해결하거나 우선순위 문제를 디버깅할 때 특히 유용해요. 다음 요청은 겹치는 인덱스 패턴을 가진 모든 적용 가능한 템플릿이 logs-sim-1이라는 인덱스에 어떻게 적용되는지 보여 줘요:

REST Python

POST /_index_template/_simulate_index/logs-sim-1

Copy Copy as cURL

response = client.indices.simulate_index_template(
name = "logs-sim-1",
body = { "Insert body here" }
)

Copy

응답 예시

{
"template": {
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "1"
}
},
"mappings": {
"properties": {
"level": {
"type": "keyword"
},
"message": {
"type": "text"
},
"timestamp": {
"type": "date"
}
}
},
"aliases": {}
},
"overlapping": []
}

응답 본문 필드

| Field | Data type | Description | | template | Object | 적용된 템플릿. | | template.settings | Object | 해석된 인덱스 설정. | | template.mappings | Object | 해석된 필드 매핑. | | template.aliases | Object | 해석된 별칭. | | overlapping | Array | 같은 인덱스 패턴과 매칭되지만 적용되지 않은 다른 인덱스 템플릿 목록. |

필수 권한

Security 플러그인을 사용한다면 적절한 권한이 있는지 확인하세요: indices:admin/index_template/simulate.

더 알아보기 (Learn more)