회사에서 기존에 많은 데이터가 담긴 인덱스의 스탑태그를 변경해줘야할 작업이 생겼다. 변경하기 위해서는 리인덱싱이 필요했는데, 이전에 리인덱싱을 해본적이 있지만 이번에는 서비스 운영을 하는 도중에 작업을 해야해서 좀 큰 작업이 되었다. 아직 실제로 돌려보기 전이고, 회사에 다른 분의 의견에 따라 alias와 reindex 를 사용하여 최대한 다운타임없이 진행을 하기로 했다. 진행하기 위해 찾아본 부분들에 대해 미리 정리를 해봤다.
기존 인덱스를 alias화 한다.
PUT /_aliases
{
"actions": [
{
"add": {
"index": "index_one",
"alias": "index_one_alias"
}
}
]
}
코드에서 사용하던 기존 인덱스명을 alias명으로 변경해준다.
매핑이 같은 인덱스 여러개를 리인덱싱해야하기 때문에 매핑을 템플릿화시켰다.
PUT _index_template/{new_template_name}
{
"index_patterns": [
"new_index_*"
],
"priority": 1,
"template": {
"mappings": {
"dynamic": "false",
"properties": {
"a_property": {
"type": "text"
},
"b_property": {
"type": "date",
"null_value": ""
},
"c_property": {
"type": "keyword"
},
"d_property": {
"type": "object"
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "2",
"analysis": {
"filter": {
"porter2": {
"name": "porter2",
"type": "stemmer"
},
"english_stop": {
"type": "stop",
"stopwords": "_english_"
},
"nori_stop": {
"type": "nori_part_of_speech",
"stoptags": [
"E",
"IC",
"J",
"MAG",
"MM",
"NA",
"NR",
"SC"
]
}
},
"analyzer": {
"K_analyzer": {
"filter": [
"nori_stop",
"porter2",
"english_stop"
],
"type": "custom",
"tokenizer": "nori_mixed"
}
},
"tokenizer": {
"nori_mixed": {
"type": "nori_tokenizer",
"decompound_mode": "mixed"
}
}
}
}
}
}
}
index_patterns
에 의하여 위 템플릿의 매핑되어 인덱스가 생성된다.PUT new_index_one
POST _reindex?wait_for_completion=false
{
"source": {
"index": "index_one"
},
"dest": {
"index": "new_index_one"
}
}
PUT /_aliases
{
"actions": [
{
"add": {
"index": "index_one",
"alias": "index_one_alias",
"is_write_index": true
}
},
{
"remove": {
"index": "new_index_one",
"alias": "index_one_alias"
}
}
]
}
DELETE /index_one