Thuta Learning
ရှာဖွေရန်
Elasticsearch
AdvancedData & Databasesbeginner

Index Templates နှင့် ILM (Index Lifecycle Management)

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Index Templates နှင့် ILM (Index Lifecycle Management) concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ Elasticsearch query/code ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် မှန်ကန်စွာအသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Application တစ်ခုက index အသစ်တွေကို repeatedly create ချရလေ့ရှိပါတယ် (ဥပမာ log data တစ်ခုစီအတွက် နေ့စဉ် index အသစ်—`logs-2026-08-29`)—index အသစ်တစ်ခုစီအတွက် mapping ကို manually ရေးရင် typo/inconsistency ဖြစ်ရလွယ်ပါတယ်။ Index template ကတော့ index name pattern (ဥပမာ `logs-*`) ကို match လုပ်တဲ့ index အသစ်တွေအတွက် mapping/settings ကို automatically apply လုပ်ပေးတဲ့ mechanism ဖြစ်ပါတယ်—template တစ်ခု define လုပ်ထားရင် index အသစ်တစ်ခု create ချတဲ့အခါ mapping ကို ထပ်မံ specify စရာမလိုတော့ပါ။ ILM (Index Lifecycle Management) ကတော့ time-series-like data (logs, metrics, event streams) ရဲ့ index တွေကို "hot" (active writes, fast storage) → "warm" (read-only, less frequent access) → "cold" (archival, cheap storage) → "delete" (retention period ကုန်ပြီး) ဆိုတဲ့ phase များကနေတစ်ဆင့် automatically transition လုပ်ပေးနိုင်ပါတယ်—single index တစ်ခုကို infinitely ကြီးထွားစေမယ့်အစား index rollover (size/age-based threshold ကျော်ရင် index အသစ်ကို auto-create) ကို ILM policy က coordinate လုပ်ပေးနိုင်ပါတယ်။ ဒါကို hard drive တစ်ခုကို full ဖြစ်အောင်ချန်ထားမယ့်အစား old file တွေကို automatic archive/cleanup schedule တစ်ခု set ထားသလိုမျိုး တွေးလို့ရပါတယ်—single index ကြီးထွားလွန်းရင် query performance ကျဆင်း/cluster management ခက်ခဲသွားနိုင်လို့ ILM က ဒီပြဿနာကို automatic လုပ်ပေးပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Tutorial Platform team က user search-query analytics event ("user X ဟာ 'redis' ရှာခဲ့တယ်") ကို daily index (`search-logs-2026-08-29`) အဖြစ် သိမ်းမယ်ဆိုပါစို့—index template တစ်ခု define ထားပြီး `search-logs-*` pattern ကိုက်ညီတဲ့ index အသစ်တိုင်းအတွက် mapping (`query`, `userId`, `timestamp` fields) automatically apply ဖြစ်စေမယ်။ ILM policy ကို "7 ရက်ကို hot phase, 30 ရက်ကို warm phase, 90 ရက်ကျော်ရင် delete" အဖြစ် သတ်မှတ်ထားမယ်—analytics data က old event log တွေကို manually delete script run စရာမလိုဘဲ retention policy အလိုအလျောက် enforce ဖြစ်နေမယ်။ Tutorial Platform ရဲ့ `tutorials` index (data volume ငယ်ပြီး time-series မဟုတ်) ကတော့ ILM မလိုအပ်ပါ—ILM ကို time-series-like data အတွက်သာ သုံးသင့်ပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

json
PUT /_index_template/search-logs-template
{
  "index_patterns": ["search-logs-*"],
  "template": {
    "mappings": {
      "properties": {
        "query":     { "type": "text" },
        "userId":    { "type": "keyword" },
        "timestamp": { "type": "date" }
      }
    },
    "settings": {
      "index.lifecycle.name": "search-logs-ilm-policy"
    }
  }
}
You should see
`search-logs-*` pattern ကိုက်ညီသော index အသစ်တိုင်းအတွက် mapping automatically apply ဖြစ်နေသော index template ရမည်။

၅ မိနစ် စမ်းကြည့်

`user-activity-*` pattern ကိုက်ညီသော index များအတွက် `eventType` (keyword), `userId` (keyword), `occurredAt` (date) fields ပါသော index template တစ်ခု design လုပ်ပါ—ILM policy name ကိုပါ settings ထဲ ထည့်ရေးပါ။

သတိလေးတစ်ချက်

Small, non-time-series index (ဥပမာ `tutorials` catalog data) ကို ILM policy တွဲပေးပြီး unnecessary rollover/phase transition complexity ထည့်ခြင်း—ILM ကို time-series-like growth pattern ရှိတဲ့ data အတွက်သာ သုံးသင့်ပါတယ်။

Index template ကို define ထားပြီးနောက် index name pattern ကို precisely match မဖြစ်အောင် (typo, wildcard မှား) ရေးမိခြင်း—template က apply မဖြစ်တော့ဘဲ dynamic mapping ကို ပြန် fallback ဖြစ်သွားနိုင်ပါတယ်။

Elasticsearch Guide — Index Lifecycle ManagementElastic

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Small, non-time-series index (ဥပမာ `tutorials` catalog data) ကို ILM policy တွဲပေးပြီး unnecessary rollover/phase transition complexity ထည့်ခြင်း—ILM ကို time-series-like growth pattern ရှိတဲ့ data အတွက်သာ သုံးသင့်ပါတယ်။
  • Index template ကို define ထားပြီးနောက် index name pattern ကို precisely match မဖြစ်အောင် (typo, wildcard မှား) ရေးမိခြင်း—template က apply မဖြစ်တော့ဘဲ dynamic mapping ကို ပြန် fallback ဖြစ်သွားနိုင်ပါတယ်။
  • နမူနာ query/mutation ကို production cluster ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test instance နှင့် recoverable data ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

`user-activity-*` pattern ကိုက်ညီသော index များအတွက် `eventType` (keyword), `userId` (keyword), `occurredAt` (date) fields ပါသော index template တစ်ခု design လုပ်ပါ—ILM policy name ကိုပါ settings ထဲ ထည့်ရေးပါ။

You'll know it worked when: `search-logs-*` pattern ကိုက်ညီသော index အသစ်တိုင်းအတွက် mapping automatically apply ဖြစ်နေသော index template ရမည်။

Index Templates နှင့် ILM (Index Lifecycle Management) | Thuta Learning