인덱스 앨리어스 생성 또는 업데이트 API (Create Or Update Index Alias API)
이 API는 하나 이상의 인덱스를 인덱스 앨리어스에 추가하거나, 기존 앨리어스의 설정을 업데이트하는 데 사용해요. 인덱스 앨리어스에 대한 더 자세한 개념은 Index aliases 문서를 참고하세요.
이 Create or Update Alias API는 앨리어스 추가·제거와 함께 인덱스의 앨리어스까지 제거하는 기능을 지원하는 Manage aliases API와는 달라요. 아래 소개할 API는 인덱스 자체를 건드리지 않고 앨리어스만 추가하거나 업데이트하는 데 그치고, 각 API는 또 서로 다른 요청 본문 파라미터를 사용합니다.
출처: OpenSearch 문서
본문
Endpoints
POST /{target}/_alias/{alias-name}
PUT /{target}/_alias/{alias-name}
POST /_alias/{alias-name}
PUT /_alias/{alias-name}
POST /{target}/_aliases/{alias-name}
PUT /{target}/_aliases/{alias-name}
POST /_aliases/{alias-name}
PUT /_aliases/{alias-name}
PUT /{target}/_alias
PUT /{target}/_aliases
PUT /_alias
Path parameters
다음 표는 사용 가능한 경로 파라미터를 보여줘요. 모든 경로 파라미터는 선택사항이에요.
| Parameter | Type | Description | | target | String | A comma-delimited list of indexes. Wildcard expressions (*) are supported. To target all indexes in a cluster, use _all or *. Optional. | | alias-name | String | The alias name to be created or updated. Optional. |
Query parameters
다음 표는 사용 가능한 쿼리 파라미터를 보여줘요. 모든 쿼리 파라미터는 선택사항이에요.
| Parameter | Type | Description | | cluster_manager_timeout | Time | The amount of time to wait for a response from the cluster manager node. Default is 30s. | | timeout | Time | The amount of time to wait for a response from the cluster. Default is 30s. |
Request body
다음 표는 사용 가능한 요청 본문 필드를 보여줘요.
| Field | Type | Description | | index | String | A comma-delimited list of indexes that you want to associate with the alias. If this field is set, it will override the index name specified in the URL path. | | alias | String | The name of the alias. If this field is set, it will override the alias name specified in the URL path. | | is_write_index | Boolean | Specifies whether the index should be a write index. An alias can only have one write index at a time. If a write request is submitted to an alias that links to multiple indexes, then OpenSearch runs the request only on the write index. | | routing | String | Assigns a custom value to a shard for specific operations. | | index_routing | String | Assigns a custom value to a shard only for index operations. | | search_routing | String | Assigns a custom value to a shard only for search operations. | | filter | Object | A filter to use with the alias so that the alias points to a filtered part of the index. |
Example request: Add a simple alias
다음 요청은 인덱스에 기본 앨리어스를 만들어요.
REST Python
PUT /products-2024/_alias/current-products
Copy Copy as cURL
response = client.indices.put_alias(
name = "current-products",
index = "products-2024",
body = { "Insert body here" }
)
Copy
Example request: Add a time-based alias
다음 요청은 sales-q1-2024 인덱스에 quarterly-2024 앨리어스를 만들어요.
REST Python
PUT /sales-q1-2024/_alias/quarterly-2024
Copy Copy as cURL
response = client.indices.put_alias(
name = "quarterly-2024",
index = "sales-q1-2024",
body = { "Insert body here" }
)
Copy
Example request: Add a filtered alias with routing
먼저 적절한 매핑을 가진 인덱스를 만들어요.
REST Python
PUT /customer-data
{
"mappings": {
"properties": {
"customer_id": {
"type": "integer"
},
"region": {
"type": "keyword"
}
}
}
}
Copy Copy as cURL
response = client.indices.create(
index = "customer-data",
body = {
"mappings": {
"properties": {
"customer_id": {
"type": "integer"
},
"region": {
"type": "keyword"
}
}
}
}
)
Copy Then add the index alias for a specific customer with routing and filtering:
REST Python
PUT /customer-data/_alias/customer-123
{
"routing": "west",
"filter": {
"term": {
"customer_id": 123
}
}
}
Copy Copy as cURL
response = client.indices.put_alias(
name = "customer-123",
index = "customer-data",
body = {
"routing": "west",
"filter": {
"term": {
"customer_id": 123
}
}
}
)
Copy
Example request: Add an alias during index creation
인덱스를 생성할 때 create index API를 사용해서 앨리어스를 함께 추가할 수도 있어요.
REST Python
PUT /inventory-2024
{
"mappings": {
"properties": {
"category": {
"type": "keyword"
}
},
"aliases": {
"current-inventory": {},
"electronics": {
"filter": {
"term": {
"category": "electronics"
}
}
}
}
Copy Copy as cURL
response = client.indices.create(
index = "inventory-2024",
body = {
"mappings": {
"properties": {
"category": {
"type": "keyword"
}
},
"aliases": {
"current-inventory": {},
"electronics": {
"filter": {
"term": {
"category": "electronics"
}
}
}
}
}
)
Copy
Example response
{
"acknowledged": true
}
Required permissions
Security 플러그인을 사용한다면 적절한 권한(indices:admin/aliases)을 가지고 있는지 확인하세요.
Related documentation
인덱스 앨리어스에 대한 더 자세한 내용은 Index aliases 문서를 참고하세요.