DBAtlas · 데이터베이스 운영 아틀라스

무중단 매핑 변경 (reindex + 원자적 alias 전환)

Elasticsearch인덱스 수명 주기

명령어

# 1) Target index with the new mapping (refresh off and replicas 0 for loading):
PUT musteri-v2
{
  "settings": { "number_of_shards": 1, "number_of_replicas": 0, "refresh_interval": "-1" },
  "mappings": { "properties": { "kod": { "type": "keyword" }, "adet": { "type": "long" } } }
}
# 2) Reindex in the background (tracked with the returned task id):
POST _reindex?wait_for_completion=false&slices=auto
{
  "source": { "index": "musteri-v1", "size": 1000 },
  "dest": { "index": "musteri-v2", "op_type": "create" },
  "conflicts": "proceed"
}
GET _tasks/<task_id>
# 3) Restore settings and compare document counts:
PUT musteri-v2/_settings
{
  "index": { "refresh_interval": null, "number_of_replicas": 1 }
}
POST musteri-v2/_refresh
GET _cat/indices/musteri-v1,musteri-v2?v&h=index,docs.count,pri.store.size
# 4) Switch the alias to the new index in one atomic operation:
POST _aliases
{
  "actions": [
    { "remove": { "index": "musteri-v1", "alias": "musteri" } },
    { "add": { "index": "musteri-v2", "alias": "musteri", "is_write_index": true } }
  ]
}

하는 일

새 매핑으로 인덱스를 만들고, reindex로 백그라운드에서 데이터를 복사하고, 문서 수를 비교한 뒤, 애플리케이션이 사용하는 alias를 한 번의 원자적 작업으로 새 인덱스로 전환한다.

사용 시점

기존 필드의 타입을 바꿔야 하거나(text -> keyword, integer -> long), analyzer를 바꿔야 하거나, 샤드 수를 다시 정해야 할 때. 이런 작업은 기존 인덱스에서 제자리로 할 수 없다.

주의

애플리케이션은 인덱스 이름이 아니라 alias로 연결해야 한다. 그렇지 않으면 전환에 배포가 필요하다. reindex 중 원본에 새로 들어온 쓰기는 대상에 도달하지 않는다: 쓰기를 중지하거나, 전환 직전에 op_type create + conflicts proceed로 reindex를 다시 실행해 공백을 메운다(이 방법으로 update와 delete는 옮겨지지 않음). reindex는 원본에 읽기 부하, 대상에 쓰기 부하를 만들므로 requests_per_second로 조절한다.

DBAtlas에서 열기 →

관련 항목