နားလည်ထားရမယ့် အချက်
Elasticsearch ရဲ့ search functionality အားလုံးကို `_search` endpoint တစ်ခုတည်းကနေ access လုပ်ရပါတယ်—Query DSL (Domain Specific Language) ဆိုတဲ့ JSON-based query language ကို request body ထဲမှာ ရေးထည့်ရပါတယ်။ `match` query ဟာ full-text search အတွက် အသုံးအများဆုံး query type ဖြစ်ပြီး search term ကို analyzer ကနေတစ်ဆင့် tokenize (lowercase, split words) လုပ်ပြီးမှ inverted index ကို compare လုပ်ပါတယ်—ဒါကြောင့် "Redis Cache" ဆိုတဲ့ search term က document ထဲက "redis" သို့ "cache" word တစ်ခုတည်းပါလည်း result ထဲပါလာနိုင်ပါတယ် (OR logic ပုံမှန်)။ ဒါဟာ `term` query (exact, un-analyzed matching) နဲ့ သိသိသာသာ ကွာပါတယ်—`term` က analyzer ကို skip လုပ်ပြီး exact value ကိုသာ compare လို့ text field ပေါ်မှာသုံးရင် အနီးစပ်မှ result များစွာ လွတ်သွားနိုင်ပါတယ်။ Response ထဲက `hits.hits` array က matched documents စာရင်းဖြစ်ပြီး document တစ်ခုစီမှာ `_score` ဆိုတဲ့ relevance score ပါလာပါတယ်—score မြင့်ရင် query နဲ့ ပိုသက်ဆိုင်တယ်လို့ ဆိုလိုပါတယ်၊ result များကို default အနေနဲ့ score အမြင့်ဆုံးကနေ sort လုပ်ထားပါတယ်။ ဒါကို Google search box နဲ့ တွေးလို့ရပါတယ်—user က keyword အများကြီး ရိုက်ထည့်လို့ document တစ်ခုစီမှာ ဘယ်လောက်နီးစပ်လဲ ranking လုပ်ပြီး ပြသတဲ့ nature တူပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial Platform ရဲ့ search box ထဲ user က "redis cache" လို့ ရိုက်ထည့်ရင် frontend က `GET /tutorials/_search` ကို `match` query ဖြင့် `title` field ပေါ်မှာ query ပို့မယ်—`term` query သုံးမယ်ဆိုရင် title ထဲက exact string "redis cache" (space, capitalization အတိအကျ) တူမှသာ match ဖြစ်မှာဖြစ်လို့ user experience ဆိုးသွားနိုင်ပါတယ်။ Response ထဲက `hits.hits[].source` ကနေ tutorial title/summary တွေကို search result card အဖြစ် render လုပ်ပြီး `_score` အလိုက် ranking လိုက်ပြသမယ်—user ရဲ့ intent နဲ့ ပိုသက်ဆိုင်တဲ့ result များကို ထိပ်ဆုံးမှာ မြင်စေချင်လို့ပါ။
အတူတူ စမ်းရေးကြည့်မယ်
GET /tutorials/_search
{
"query": {
"match": {
"title": "redis cache"
}
}
}`hits.hits` array ထဲမှာ `title` field က "redis" သို့ "cache" word ပါသော tutorial documents စာရင်းကို `_score` ဖြင့် sort လုပ်ထားပြီးရမည်။၅ မိနစ် စမ်းကြည့်
`tags` field ပေါ်မှာ "database" ဆိုတဲ့ term ကို `match` query ဖြင့်ရှာသော request ရေးပြီး၊ အတူတူ term ကိုပဲ `term` query ဖြင့်ရှာရင် result ကွာနိုင်တဲ့ scenario တစ်ခု ဥပမာပေးပါ။
သတိလေးတစ်ချက်
`text` type field ပေါ်မှာ exact match လိုချင်ပြီး `term` query သုံးမိခြင်း—analyzer ကို skip လုပ်ထားလို့ document ထဲက indexed token (lowercase, stemmed) နဲ့ query value (original casing) မကိုက်ဘဲ result လုံးဝမရနိုင်ပါ။
`match` query ရဲ့ default behavior က OR logic ဖြစ်တာကို မသိဘဲ multi-word search term ရိုက်ထည့်ရင် word အားလုံးပါမှ match ဖြစ်မယ်လို့ (AND logic) မှားထင်ခြင်း။
Elasticsearch Guide — Search Your Data — Elastic