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

인덱스 클론 API (Clone Index API)

원문 보기 위키 갱신

clone index API는 기존 인덱스를 새 인덱스로 클론하며, 이때 각 원본 기본(primary) 샤드가 대상 인덱스의 새 기본 샤드로 클론됩니다.

이 API를 다음 시나리오에서 사용해요.

  • 파괴적인 변경을 하기 전에 같은 수의 샤드를 가진 인덱스 백업 복사본을 만들 때.

  • 원본 인덱스를 보존하면서 클론된 복사본에서 설정 변경을 테스트할 때.

  • 다른 설정이나 앨리어스를 가진 병렬 처리 워크플로우를 위해 인덱스를 복제할 때. 클론 연산은 인덱스 데이터를 효율적으로 복제하기 위해 세 단계 프로세스를 따릅니다.

  • OpenSearch는 매핑과 설정을 포함해 소스 인덱스와 동일한 정의로 대상 인덱스를 만듭니다.

  • 시스템은 소스 인덱스 세그먼트에서 대상 인덱스로 하드 링크를 생성합니다. 파일 시스템이 하드 링크를 지원하지 않으면 OpenSearch는 모든 세그먼트를 대상 인덱스로 복사하는데, 이는 더 많은 시간과 디스크 공간이 필요합니다.

  • OpenSearch는 대상 인덱스를 재개방된 클로즈드 인덱스처럼 복구해 사용 가능하게 만듭니다.

출처: OpenSearch 문서

본문

Prerequisites

인덱스를 클론하기 전에 소스 인덱스를 읽기 전용으로 표시하고 클러스터가 정상 상태인지 확인해야 해요.

  • 소스 인덱스는 index.blocks.write 설정이 true여야 클론 과정 중 쓰기 연산을 막을 수 있습니다. 인덱스 삭제와 같은 메타데이터 변경은 여전히 허용됩니다.
  • 클러스터 헬스 상태가 green이어야 모든 기본 및 복제 샤드가 사용 가능함을 보장할 수 있어요. 다음 예시 요청은 products 인덱스를 읽기 전용 모드로 설정해 클론할 수 있게 합니다.

REST Python

PUT /products/_settings
{
"settings": {
"index.blocks.write": true
}
}

Copy Copy as cURL

response = client.indices.put_settings(
index = "products",
body =   {
"settings": {
"index.blocks.write": true
}
}
)

Copy

Endpoints

POST /{index}/_clone/{target}
PUT  /{index}/_clone/{target}

Requirements

인덱스는 다음 요구 사항을 충족할 때만 클론할 수 있어요.

  • 대상 인덱스가 아직 존재하지 않아야 합니다.
  • 소스 인덱스는 대상 인덱스와 같은 수의 기본 샤드를 가져야 합니다.
  • 소스 인덱스는 index.blocks.write를 true로 설정해 읽기 전용으로 표시되어야 합니다.
  • 클러스터 헬스 상태가 green이어야 합니다.
  • 클론 과정을 처리하는 노드는 파일 시스템이 하드 링크를 지원하지 않는 경우 인덱스의 두 번째 복사본을 수용할 충분한 여유 디스크 공간이 있어야 합니다.

Index naming restrictions

OpenSearch 인덱스에는 다음 이름 제한이 있습니다.

  • 모든 글자는 소문자여야 합니다.
  • 인덱스 이름은 밑줄(_)이나 하이픈(-)으로 시작할 수 없습니다.
  • 인덱스 이름은 공백, 쉼표 또는 다음 문자를 포함할 수 없습니다.

:, ", *, +, /, , |, ?, #, >, or <

Path parameters

다음 표는 사용 가능한 경로 파라미터를 보여줘요.

| Parameter | Required | Data type | Description | | index | Required | String | The name of the source index to clone. | | target | Required | String | The name of the target index to create. |

Query parameters

다음 표는 사용 가능한 쿼리 파라미터를 보여줘요. 모든 쿼리 파라미터는 선택사항이에요.

| Parameter | Data type | Description | Default | | cluster_manager_timeout | String | The amount of time to wait for a connection to the cluster manager node. | 30s | | task_execution_timeout | String | The amount of time to wait for the task to complete. Only applicable when wait_for_completion is set to false. | 1h | | timeout | String | The amount of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. | 30s | | wait_for_active_shards | String | The number of active shard copies required for the operation to proceed. Specify all or any positive integer up to the total number of shards in the index (number_of_replicas+1). | 1 (only the primary shard) | | wait_for_completion | Boolean | Specifies whether to wait for the operation to complete before returning a response. | true |

Request body fields

clone index API는 새 대상 인덱스를 만들므로 요청 본문에서 대상 인덱스에 적용할 인덱스 설정과 앨리어스를 지정할 수 있어요. 요청 본문은 선택사항입니다.

| Field | Data type | Description | | settings | Object | Configuration options for the target index. For a list of index settings, see Index settings. Optional. | | settings.index.number_of_shards | Integer | The number of primary shards in the target index. This value must equal the number of primary shards in the source index. Optional. Default is the same as the source index. | | settings.index.number_of_replicas | Integer | The number of replica shards for each primary shard in the target index. Optional. Default is the same as the source index. | | aliases | Object | Index aliases to apply to the target index. Each key is an alias name, and the value is an alias configuration object. For more information, see Index aliases. Optional. | Note: 클론 요청에는 매핑을 지정할 수 없어요. 소스 인덱스의 매핑이 대상 인덱스에 자동으로 사용됩니다.

Example: Cloning an index

다음 예시 요청은 products 인덱스를 products-clone이라는 새 인덱스로 클론해요.

REST Python

POST /products/_clone/products-clone
{}

Copy Copy as cURL

response = client.indices.clone(
index = "products",
target = "products-clone",
body =   {}
)

Copy

Example: Cloning an index with settings and aliases

다음 예시 요청은 products 인덱스를 커스텀 설정과 앨리어스를 가진 products-clone-configured라는 새 인덱스로 클론해요.

REST Python

POST /products/_clone/products-clone-configured
{
"settings": {
"index": {
"number_of_shards": 2,
"number_of_replicas": 1
}
},
"aliases": {
"products-search": {}
}
}

Copy Copy as cURL

response = client.indices.clone(
index = "products",
target = "products-clone-configured",
body =   {
"settings": {
"index": {
"number_of_shards": 2,
"number_of_replicas": 1
}
},
"aliases": {
"products-search": {}
}
}
)

Copy

Example response

클론 요청이 성공하면 OpenSearch는 다음 응답을 반환합니다. index 필드는 생성된 대상 인덱스의 이름을 담고 있어요.

{
"acknowledged": true,
"shards_acknowledged": true,
"index": "products-clone"
}

대상 인덱스가 클러스터 상태에 추가되면 응답은 즉시 반환됩니다. 클론 연산이 완료될 때까지 기다리지는 않아요.

Response body fields

다음 표는 모든 응답 본문 필드를 보여줘요.

| Field | Data type | Description | | acknowledged | Boolean | Indicates whether the clone request was received by the cluster. A value of true means the request was received. | | shards_acknowledged | Boolean | Indicates whether the number of shard copies specified by the wait_for_active_shards setting became active before the operation timed out. A value of true means the target number of shard copies became active. A value of false means that the operation timed out before the target number of shard copies became active. | | index | String | The name of the newly created target index. |

Monitoring the cloning process

clone API는 대상 인덱스를 클러스터 상태에 추가하면 샤드가 할당되기 전에 즉시 응답을 반환합니다. 이 시점에서 모든 샤드는 unassigned 상태입니다. 어떤 이유로든 대상 인덱스를 할당할 수 없으면 기본 샤드는 노드에 할당될 수 있을 때까지 할당되지 않은 상태로 유지됩니다.

기본 샤드가 할당되면 initializing 상태로 전환되고 클론 연산이 시작됩니다. 클론 연산이 완료되면 샤드는 active가 됩니다. 그러면 OpenSearch가 복제본 할당을 시도하고 기본 샤드를 다른 노드로 재배치할 수 있어요.

다음 방법 중 하나로 클론 과정을 모니터링할 수 있습니다.

  • 샤드 복구 및 클론의 진행 상황을 보려면 CAT recovery API를 사용하세요.
  • 모든 기본 샤드가 할당될 때까지 기다리려면 wait_for_status를 yellow로 설정한 Cluster health API를 사용하세요. 다음 예시 요청은 클론된 인덱스의 복구 과정을 모니터링해요.

REST Python

GET /_cat/recovery/products-clone?v

Copy Copy as cURL

response = client.cat.recovery(
index = "products-clone",
params = { "v": "true" }
)

Copy

Wait for active shards

클론 연산은 새 인덱스를 만들므로 인덱스 생성의 wait_for_active_shards 설정도 클론 연산에 적용됩니다. 이 설정은 연산이 응답을 반환하기 전에 몇 개의 샤드 복사본이 활성화되어야 하는지를 결정합니다. 자세한 내용은 Index settings 문서를 참고하세요.

Required permissions

Security 플러그인을 사용한다면 적절한 권한(indices:admin/resize)을 가지고 있는지 확인하세요.

더 알아보기 (Learn more)