နားလည်ထားရမယ့် အချက်
Mapping တစ်ခု (ဥပမာ field type) ကို index ဖန်တီးပြီးသားတစ်ခုပေါ်မှာ တိုက်ရိုက် ပြောင်းလို့ မရပါ—inverted index ကို field type အလိုက် ကြိုတည်ဆောက်ထားလို့ type ပြောင်းချင်ရင် document အားလုံးကို index အသစ်တစ်ခုထဲ ပြန် reindex လုပ်ရပါတယ်။ Elasticsearch ရဲ့ `_reindex` API က source index ထဲက document အားလုံးကို destination index (mapping အသစ်ပါတဲ့) ထဲ copy ချပေးနိုင်ပြီး၊ ဒီအလုပ်ကို downtime မဖြစ်စေချင်ရင် "alias" ဆိုတဲ့ pointer concept ကို သုံးရပါတယ်—application code က index name အစစ် (`tutorials_v1`) ကို တိုက်ရိုက် reference မလုပ်ဘဲ alias name (`tutorials`) ကိုသာ query လုပ်ထားရင် reindex ပြီးတဲ့အခါ alias ကို index အသစ် (`tutorials_v2`) ဆီ atomic swap လုပ်ရုံနဲ့ application code ဘာမှ ပြောင်းစရာမလိုဘဲ zero-downtime migration ရနိုင်ပါတယ်။ Reindexing operation ကို large dataset ပေါ်မှာ run တဲ့အခါ internally `_bulk` API ကိုသုံးထားလို့ Lesson 5 က `_bulk` mechanics (chunking, per-item error checking) အားလုံးက ဒီနေရာမှာ ဆက်သက်ဆိုင်ပါတယ်—document count များလွန်းရင် reindex operation ကလည်း background task အဖြစ် run ပြီး progress ကို polling လုပ်ရနိုင်ပါတယ်။ ဒါကို house ကို renovate လုပ်တဲ့အခါ house အဟောင်းထဲမှာနေရင်း (downtime မဖြစ်ဘဲ) house အသစ်ကို ဘေးနားမှာ ဆောက်ပြီး ပြီးမှ address sign (alias) ကို ချိန်းပြောင်းတာနဲ့ တွေးလို့ရပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial Platform team က `body` field ကို analyzer ပြောင်းချင်တယ်ဆိုပါစို့ (`standard` ကနေ `english` ဆီ)—analyzer ပြောင်းခြင်းဟာလည်း mapping ပြောင်းခြင်းလိုပဲ existing documents ကို reindex ပြန်လုပ်ရမယ့် operation ဖြစ်ပါတယ်။ `tutorials_v2` index ကို analyzer အသစ်ပါတဲ့ mapping နဲ့ ဦးစွာဖန်တီး၊ `_reindex` API ကို `tutorials_v1` ကနေ `tutorials_v2` ဆီ run ၊ document count နှစ်ခု (`_count` API ဖြင့်) တူညီမှန်ကန်ကြောင်း verify လုပ်ပြီးမှ `tutorials` alias ကို `tutorials_v1` ကနေ `tutorials_v2` ဆီ atomic (single `_aliases` API call ထဲမှာ remove+add) ပြောင်းမယ်—application code ရဲ့ `GET /tutorials/_search` request တွေ interruption လုံးဝ မခံစားရအောင်ပါ။
အတူတူ စမ်းရေးကြည့်မယ်
PUT /tutorials_v2
{
"mappings": {
"properties": {
"body": { "type": "text", "analyzer": "english" }
}
}
}
POST /_reindex
{
"source": { "index": "tutorials_v1" },
"dest": { "index": "tutorials_v2" }
}
POST /_aliases
{
"actions": [
{ "remove": { "index": "tutorials_v1", "alias": "tutorials" } },
{ "add": { "index": "tutorials_v2", "alias": "tutorials" } }
]
}Analyzer အသစ်ပါသော `tutorials_v2` index ထဲသို့ document အားလုံး copy ဖြစ်ပြီး `tutorials` alias က downtime မရှိဘဲ index အသစ်ဆီ ချိန်းပြောင်းမည်။၅ မိနစ် စမ်းကြည့်
`lessonCount` field ကို `integer` ကနေ `long` ပြောင်းချင်တယ်ဆိုပါစို့—`tutorials_v3` index ဖန်တီးခြင်း၊ reindex လုပ်ခြင်း၊ document count verify လုပ်ခြင်း၊ alias swap လုပ်ခြင်း—အဆင့်လေးခုကို request sequence အဖြစ်ရေးပါ။
သတိလေးတစ်ချက်
Existing index ရဲ့ mapping field type ကို `PUT /_mapping` ဖြင့် တိုက်ရိုက်ပြောင်းနိုင်တယ်လို့ ထင်ခြင်း—field type ပြောင်းလိုချင်ရင် reindex ချည်းသာ တစ်ခုတည်း ဖြေရှင်းနည်း ဖြစ်ပါတယ်။
Alias swap မလုပ်ဘဲ application code ထဲက index name ကို hardcode ထားခြင်း (`tutorials_v1` ကို တိုက်ရိုက် reference)—reindex/migration လုပ်တိုင်း application code ကို redeploy ပြန်လုပ်ရမယ့် unnecessary coupling ဖြစ်စေပါတယ်။
Elasticsearch Guide — Reindex API — Elastic