Manage Aliases API (별칭 관리 API)
하나의 요청 안에서 인덱스 별칭(alias) 작업을 여러 개 한꺼번에 처리해야 할 때 사용하는 API예요. 별칭을 추가하거나 제거하고, 별칭이 가리키는 인덱스를 다른 인덱스로 바꾸거나, 별칭 관리를 하면서 동시에 인덱스를 삭제하는 복잡한 작업을 하나의 원자적(atomic) 트랜잭션으로 묶어서 처리할 수 있어요. 여러 작업을 동시에 해야 하는 경우에는 이 API가 특히 유용합니다.
이 API는 한 번에 하나의 별칭만 다루는 Create or update alias API와는 달라요. 별칭 하나만 다루는 작업이라면 그 API를, 여러 별칭이나 인덱스를 묶어서 원자적으로 처리해야 한다면 이 Manage aliases API를 쓰면 됩니다. 인덱스 별칭에 대한 개념 설명과 사용 사례는 Index aliases 문서를 참고해 주세요.
출처: OpenSearch 문서
본문
Endpoints
POST _aliases
Query parameters
다음 표는 사용할 수 있는 쿼리 파라미터 목록이에요. 모든 쿼리 파라미터는 선택 사항입니다.
| Parameter | Data 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 fields
다음 표는 요청 본문에서 사용할 수 있는 필드 목록이에요.
| Field | Data type | Description | Required | | actions | Array | Set of actions you want to perform on the index. Valid options are: add, remove, and remove_index. You must have at least one action in the array. | Yes | | add | N/A | Adds an alias to the specified index. | No | | remove | N/A | Removes an alias from the specified index. | No | | remove_index | N/A | Deletes an index. | No | | index | String | Name of the index you want to associate with the alias. Supports wildcard expressions. | Yes if you don’t supply an indices field in the body. | | indices | Array | Array of index names you want to associate with the alias. | Yes if you don’t supply an index field in the body. | | alias | String | The name of the alias. | Yes if you don’t supply an aliases field in the body. | | aliases | Array | Array of alias names. | Yes if you don’t supply an alias field in the body. | | filter | Object | A filter to use with the alias, so the alias points to a filtered part of the index. | No | | is_hidden | Boolean | Specifies whether the alias should be hidden from results that include wildcard expressions | No | | must_exist | Boolean | Specifies whether the alias to remove must exist. | No | | 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 a alias that links to multiple indexes, OpenSearch executes the request only on the write index. Important: Aliases that don’t explicitly set is_write_index: true for an index and only reference one index will have that index behave as the write index until another index is referenced. At that point, there will be no write index and writes will be rejected. | No | | routing | String | Used to assign a custom value to a shard for specific operations. | No | | index_routing | String | Assigns a custom value to a shard only for index operations. | No | | search_routing | String | Assigns a custom value to a shard only for search operations. | No |
Example: Add an alias
다음 요청은 application_logs_2024 인덱스를 가리키는 logs_current라는 별칭을 만듭니다.
REST Python
POST /_aliases
{
"actions": [
{
"add": {
"index": "application_logs_2024",
"alias": "logs_current"
}
}
]
}
Copy Copy as cURL
response = client.indices.update_aliases(
body = {
"actions": [
{
"add": {
"index": "application_logs_2024",
"alias": "logs_current"
}
}
]
}
)
Copy
Example: Remove an alias
다음 요청은 application_logs_2024 인덱스에서 logs_current 별칭을 제거합니다.
REST Python
POST /_aliases
{
"actions": [
{
"remove": {
"index": "application_logs_2024",
"alias": "logs_current"
}
}
]
}
Copy Copy as cURL
response = client.indices.update_aliases(
body = {
"actions": [
{
"remove": {
"index": "application_logs_2024",
"alias": "logs_current"
}
}
]
}
)
Copy
Example: Rename an alias
별칭을 한 인덱스에서 제거하고 같은 요청 안에서 다른 인덱스에 다시 추가하면 별칭 이름을 원자적으로 바꿀 수 있어요. 다음 예제는 primary_data 별칭을 dataset_v1에서 dataset_v2로 옮깁니다.
POST /_aliases
{
"actions": [
{
"remove": {
"index": "dataset_v1",
"alias": "primary_data"
}
},
{
"add": {
"index": "dataset_v2",
"alias": "primary_data"
}
]
}
copy
별칭 작업은 원자적이라서 primary_data가 두 인덱스를 동시에 가리키거나 둘 다 가리키지 않는 순간은 존재하지 않아요.
Example: Add an alias to multiple indexes
하나의 별칭을 add 액션 여러 개로 나눠서 여러 인덱스에 연결할 수도 있어요.
POST /_aliases
{
"actions": [
{
"add": {
"index": "products_electronics",
"alias": "all_products"
}
},
{
"add": {
"index": "products_clothing",
"alias": "all_products"
}
},
{
"add": {
"index": "products_books",
"alias": "all_products"
}
]
}
copy
Example: Use the indices array
또는 indices 배열을 사용해 하나의 액션 안에서 여러 인덱스를 지정할 수도 있습니다.
POST /_aliases
{
"actions": [
{
"add": {
"indices": ["products_electronics", "products_clothing", "products_books"],
"alias": "all_products"
}
}
]
}
copy
Example: Use wildcard patterns
와일드카드 패턴을 사용하면 이름 규칙이 맞는 여러 인덱스를 한 번에 추가할 수 있어요. 다음 예제는 sales_2024로 시작하는 모든 인덱스를 위한 별칭을 만듭니다.
POST /_aliases
{
"actions": [
{
"add": {
"index": "sales_2024_*",
"alias": "current_year_sales"
}
}
]
}
copy
이렇게 하면 생성 시점에 패턴과 일치하던 인덱스들만 포함하는 특정 시점(point-in-time) 별칭이 만들어져요. 나중에 같은 패턴으로 새 인덱스를 만들어도 자동으로 포함되지는 않습니다.
별칭이 여러 인덱스를 가리키는데 쓰기 인덱스(write index)를 지정하지 않으면 그 별칭에 쓰기를 하는 것은 오류가 됩니다.
Example: Index swapping
인덱스를 새 것으로 교체할 때 다운타임 없이 원자적으로 바꿀 수 있어요. 재인덱싱(reindexing) 작업에서 유용합니다.
POST /_aliases
{
"actions": [
{
"add": {
"index": "customer_data_new",
"alias": "customer_data"
}
},
{
"remove_index": {
"index": "customer_data_old"
}
]
}
copy
이 작업은 새 인덱스를 별칭에 추가하고 옛 인덱스를 삭제하는 일을 하나의 원자적 작업으로 처리합니다.
Example: Filtered aliases
필터링된 별칭(Filtered alias)을 사용하면 쿼리 필터를 적용해서 인덱스 안의 데이터를 세그먼트로 나눌 수 있어요. 데이터의 특정 부분집합만 별도의 별칭 이름으로 접근하게 할 수 있죠. 먼저 인덱스에 필요한 필드 매핑이 있는지 확인합니다.
PUT /user_activity
{
"mappings": {
"properties": {
"user_type": {
"type": "keyword"
},
"timestamp": {
"type": "date"
},
"action": {
"type": "keyword"
}
}
}
}
copy
그 다음 필터링된 별칭을 만들어 데이터를 나눠 보세요.
POST /_aliases
{
"actions": [
{
"add": {
"index": "user_activity",
"alias": "premium_users",
"filter": {
"term": {
"user_type": "premium"
}
}
},
{
"add": {
"index": "user_activity",
"alias": "recent_activity",
"filter": {
"range": {
"timestamp": {
"gte": "now-7d"
}
}
}
}
]
}
copy
이런 별칭들은 지정된 필터를 모든 검색, 카운트, delete by query 작업에 자동으로 적용합니다.
Example: Basic routing
라우팅(routing)을 사용하면 작업을 특정 샤드로 보낼 수 있어서, 쿼리해야 하는 샤드 수를 줄여 성능을 높일 수 있어요.
다음 예제는 라우팅 값을 가진 별칭을 만듭니다.
POST /_aliases
{
"actions": [
{
"add": {
"index": "customer_orders",
"alias": "region_east_orders",
"routing": "east"
}
}
]
}
copy
Example: Separate routing for index and search operations
인덱싱과 검색에 서로 다른 라우팅 값을 지정할 수 있어요.
POST /_aliases
{
"actions": [
{
"add": {
"index": "user_sessions",
"alias": "mobile_sessions",
"index_routing": "mobile",
"search_routing": "mobile,tablet"
}
}
]
}
copy
이 예제에서는 별칭을 통해 인덱싱되는 모든 문서가 "mobile" 샤드로 가지만, 검색은 "mobile"과 "tablet" 샤드를 모두 조회할 수 있습니다.
별칭 라우팅과 routing 파라미터를 함께 사용해 검색하면 OpenSearch는 두 값의 교집합을 사용해요. 예를 들어 GET /mobile_sessions/_search?routing=tablet,mobile로 검색하면, 별칭 라우팅(mobile,tablet)과 검색 파라미터(tablet,mobile)의 교집합인 "mobile" 라우팅 값만 사용됩니다.
Example: Setting a write index
별칭이 여러 인덱스를 가리킬 때는 어떤 인덱스가 쓰기 작업을 처리할지 지정해야 합니다.
POST /_aliases
{
"actions": [
{
"add": {
"index": "logs_2024_01",
"alias": "active_logs",
"is_write_index": true
}
},
{
"add": {
"index": "logs_2024_02",
"alias": "active_logs",
"is_write_index": false
}
]
}
copy
이제 별칭에 쓰기를 하면 모든 쓰기 작업이 logs_2024_01로 갑니다.
POST /active_logs/_doc
{
"timestamp": "2024-01-15T10:30:00",
"level": "INFO",
"message": "Application started successfully"
}
copy
Example: Switch the write index
어떤 인덱스가 쓰기 인덱스 역할을 하는지 원자적으로 바꿀 수 있어요.
POST /_aliases
{
"actions": [
{
"add": {
"index": "logs_2024_01",
"alias": "active_logs",
"is_write_index": false
}
},
{
"add": {
"index": "logs_2024_02",
"alias": "active_logs",
"is_write_index": true
}
]
}
copy
쓰기 인덱스를 다룰 때 다음 사항들을 꼭 기억해 두세요.
- 별칭은 한 번에 하나의 쓰기 인덱스만 가질 수 있어요.
- 별칭이 쓰기 인덱스를 지정하지 않고 여러 인덱스를 가리키면 쓰기 작업은 거부됩니다.
- 별칭이 단일 인덱스만 가리키면 그 인덱스가 자동으로 쓰기 인덱스 역할을 합니다.
Example: Use the must_exist parameter
OpenSearch는 remove 작업을 위해 must_exist 파라미터를 제공하는데, 존재하지 않는 별칭을 제거할 때의 오류 처리를 제어합니다.
POST /_aliases
{
"actions": [
{
"remove": {
"index": "application_logs_2024",
"alias": "logs_current",
"must_exist": true
}
}
]
}
copy
- must_exist: true - 별칭이 존재하지 않으면 오류를 던집니다
- must_exist: false - 별칭이 존재하지 않아도 조용히 성공 처리합니다
- must_exist: null (기본값) - 지정된 별칭이 하나도 없을 때만 오류를 던집니다
Example response
성공한 모든 별칭 작업은 같은 응답 형식을 반환합니다.
{
"acknowledged": true
}
Required permissions
Security 플러그인을 사용한다면 indices:admin/aliases/get 권한이 있는지 확인하세요.
Related documentation
인덱스 별칭에 대한 자세한 내용은 Index aliases 문서를 참고하세요.
더 알아보기 (Learn more)
인덱스 별칭을 더 깊이 이해하고 싶다면 OpenSearch의 Index aliases 문서에서 개념과 다양한 활용 사례를 확인해 보세요. 별칭 하나만 다루는 단순한 작업이라면 Create or update alias API를, 여러 작업을 하나로 묶어야 한다면 이 Manage Aliases API를 선택하면 됩니다.