Mapping & Dynamic Mapping
1️⃣ Mapping কি?
Mapping = Index এর structure বা schema
কোন field কোন type হবে (text, keyword, number, date ইত্যাদি)
কোন field analyzed হবে কি না (searchable কি শুধু stored)
উদাহরণ:
{
"mappings": {
"properties": {
"name": { "type": "text" },
"age": { "type": "integer" },
"joined_date": { "type": "date" }
}
}
}
এখানে আমরা index create করার সময় field type declare করেছি।
2️⃣ Dynamic Mapping কি?
Dynamic Mapping = OpenSearch automatic ভাবে new field detect করে এবং type assign করে।
তুমি যদি নতুন field insert করো যেটা আগে mapping-এ নেই → OpenSearch নিজেই decide করবে field type।
উদাহরণ:
1️⃣ Index তৈরি করো (Mapping declare ছাড়া):
PUT /students
{
"mappings": {
"dynamic": true
}
}
2️⃣ Document insert করো:
POST /students/_doc
{
"name": "Ali",
"age": 23,
"joined_date": "2026-03-12",
"department": "CSE"
}
departmentfield আগেই mapping-এ ছিল না।Dynamic Mapping active থাকায় OpenSearch automatically
departmentfield কেtexttype হিসেবে create করল।
3️⃣ Dynamic Mapping-এর Rules
Numbers: যদি number value দেন →
integerবাfloatহবে।String: যদি text দিলে →
texttype।Boolean: true/false দিলে →
booleantype।Date: ISO format (2026-03-12) দিলে →
datetype।Objects / Nested JSON: OpenSearch nested mapping বানাবে।
4️⃣ Dynamic Mapping Options
1️⃣ dynamic: true
ডিফল্ট।
নতুন field auto detect হবে।
2️⃣ dynamic: false
নতুন field ignore হবে।
শুধু আগে declared field update হবে।
3️⃣ dynamic: strict
যদি নতুন field আসে → error generate হবে।
Useful for production যেখানেই unknown field accept করা যাবে না।
উদাহরণ:
PUT /students
{
"mappings": {
"dynamic": "strict",
"properties": {
"name": { "type": "text" }
}
}
}
যদি তুমি
ageinsert করো → OpenSearch error দিবে।
5️⃣ Dynamic Mapping এর সুবিধা
✅ Auto field detection → schema declare না করেও ডেটা insert করতে পারো
✅ Flexible → নতুন field আসলেও system crash হবে না
✅ Rapid prototyping → প্রথমে test data insert করা সহজ
Limitations:
বড় project বা production → recommended strict mapping + manual mapping
Auto-detected type ভুল হতে পারে → পরে query error হতে পারে
6️⃣ Professional Example
PUT /employees
{
"mappings": {
"dynamic": true,
"properties": {
"name": { "type": "text" },
"salary": { "type": "float" }
}
}
}
POST /employees/_doc
{
"name": "Sara",
"salary": 50000,
"department": "IT", <-- dynamic mapping auto created
"joining_date": "2026-03-12" <-- auto detected as date
}
department→textjoining_date→date
💡 Tip:
Learning: প্রথমে dynamic:true দিয়ে practice করো
Production: mapping explicitly declare করো + dynamic:false/strict
****************************************************************************
"title": {
"type": "text",
"analyzer": "standard"
}
ঠিক আছে! এবার আমি তোমাকে OpenSearch-এ analyzer property সম্পূর্ণ সহজভাবে ব্যাখ্যা করি, step by step, উদাহরণসহ।
1️⃣ Analyzer মানে কি?
Analyzer = text কে small pieces বা tokens এ ভাগ করার নিয়ম।
OpenSearch যখন text type field index করে → সেটা analyze করে।
Analyze মানে: শব্দগুলোকে ছোট ছোট অংশে ভেঙে, stop words বাদ দেওয়া, lowercase করা ইত্যাদি।
এর মাধ্যমে search efficient হয়।
উদাহরণ:
"The Quick Brown Fox"
Standard analyzer → ["the", "quick", "brown", "fox"]
Lowercase করে → ["the", "quick", "brown", "fox"]
Stop words remove করলে → ["quick", "brown", "fox"]
2️⃣ Analyzer কবে ব্যবহার হয়?
শুধু
textfield type এর জন্য।উদাহরণ Mapping:
"title": { "type": "text", "analyzer": "standard" }যখন তুমি search করবে → এই analyzer ব্যবহার করে text tokenized হবে।
3️⃣ Predefined/Default Analyzers
OpenSearch এ কিছু common analyzer আছে:
| Analyzer Name | ব্যাখ্যা |
|---|---|
standard | Default, English stop words, lowercase, tokenization |
simple | শুধু lowercase, punctuation remove |
whitespace | শুধু whitespace (space) দিয়ে split করে |
stop | English stop words remove করে (like “the”, “is”) |
keyword | পুরো string as-is রাখে, কোনো tokenization না করে |
pattern | Regular expression ব্যবহার করে tokenize |
fingerprint | duplicate detection, normalize করে |
language | language-specific analyzer, যেমন english, spanish |
4️⃣ Example Mapping with Different Analyzers
PUT /books
{
"mappings": {
"properties": {
"title_standard": { "type": "text", "analyzer": "standard" },
"title_whitespace": { "type": "text", "analyzer": "whitespace" },
"title_keyword": { "type": "text", "analyzer": "keyword" }
}
}
}
5️⃣ Sample Input Document
POST /books/_doc
{
"title_standard": "The Quick Brown Fox",
"title_whitespace": "The Quick Brown Fox",
"title_keyword": "The Quick Brown Fox"
}
title_standard→ ["the", "quick", "brown", "fox"]title_whitespace→ ["The", "Quick", "Brown", "Fox"]title_keyword→ ["The Quick Brown Fox"]
💡 দেখছো: keyword analyzer পুরো string একটিমাত্র token হিসেবে রাখে।
6️⃣ Professional Tip
Full-text search →
standardবা language-specific analyzerFilter/Exact match →
keywordSpecial cases →
patternবা custom analyzer