Header Ads

Header ADS

Mapping & Dynamic Mapping

 1️⃣ Mapping কি?

Mapping = Index এর structure বা schema

  1. কোন field কোন type হবে (text, keyword, number, date ইত্যাদি)

  2. কোন field analyzed হবে কি না (searchable কি শুধু stored)

উদাহরণ:

{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "age": { "type": "integer" },
      "joined_date": { "type": "date" }
    }
  }
}
  1. এখানে আমরা index create করার সময় field type declare করেছি


2️⃣ Dynamic Mapping কি?

  1. Dynamic Mapping = OpenSearch automatic ভাবে new field detect করে এবং type assign করে

  2. তুমি যদি নতুন 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"
}
  1. department field আগেই mapping-এ ছিল না।

  2. Dynamic Mapping active থাকায় OpenSearch automatically department field কে text type হিসেবে create করল।


3️⃣ Dynamic Mapping-এর Rules

  1. Numbers: যদি number value দেন → integer বা float হবে।

  2. String: যদি text দিলে → text type।

  3. Boolean: true/false দিলে → boolean type।

  4. Date: ISO format (2026-03-12) দিলে → date type।

  5. Objects / Nested JSON: OpenSearch nested mapping বানাবে।


4️⃣ Dynamic Mapping Options

1️⃣ dynamic: true

  1. ডিফল্ট।

  2. নতুন field auto detect হবে।

2️⃣ dynamic: false

  1. নতুন field ignore হবে।

  2. শুধু আগে declared field update হবে।

3️⃣ dynamic: strict

  1. যদি নতুন field আসে → error generate হবে

  2. Useful for production যেখানেই unknown field accept করা যাবে না।

উদাহরণ:

PUT /students
{
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "name": { "type": "text" }
    }
  }
}
  1. যদি তুমি age insert করো → OpenSearch error দিবে।


5️⃣ Dynamic Mapping এর সুবিধা

✅ Auto field detection → schema declare না করেও ডেটা insert করতে পারো
✅ Flexible → নতুন field আসলেও system crash হবে না
✅ Rapid prototyping → প্রথমে test data insert করা সহজ

Limitations:

  1. বড় project বা production → recommended strict mapping + manual mapping

  2. 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
}
  1. departmenttext

  2. joining_datedate


💡 Tip:

  1. Learning: প্রথমে dynamic:true দিয়ে practice করো

  2. 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 এ ভাগ করার নিয়ম।

  1. OpenSearch যখন text type field index করে → সেটা analyze করে।

  2. Analyze মানে: শব্দগুলোকে ছোট ছোট অংশে ভেঙে, stop words বাদ দেওয়া, lowercase করা ইত্যাদি।

  3. এর মাধ্যমে search efficient হয়।

উদাহরণ:

"The Quick Brown Fox"
  1. Standard analyzer → ["the", "quick", "brown", "fox"]

  2. Lowercase করে → ["the", "quick", "brown", "fox"]

  3. Stop words remove করলে → ["quick", "brown", "fox"]


2️⃣ Analyzer কবে ব্যবহার হয়?

  1. শুধু text field type এর জন্য।

  2. উদাহরণ Mapping:

  3. "title": {
      "type": "text",
      "analyzer": "standard"
    }
    
  4. যখন তুমি search করবে → এই analyzer ব্যবহার করে text tokenized হবে।


3️⃣ Predefined/Default Analyzers

OpenSearch এ কিছু common analyzer আছে:

Analyzer Nameব্যাখ্যা
standardDefault, English stop words, lowercase, tokenization
simpleশুধু lowercase, punctuation remove
whitespaceশুধু whitespace (space) দিয়ে split করে
stopEnglish stop words remove করে (like “the”, “is”)
keywordপুরো string as-is রাখে, কোনো tokenization না করে
patternRegular expression ব্যবহার করে tokenize
fingerprintduplicate detection, normalize করে
languagelanguage-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"
}
  1. title_standard → ["the", "quick", "brown", "fox"]

  2. title_whitespace → ["The", "Quick", "Brown", "Fox"]

  3. title_keyword → ["The Quick Brown Fox"]

💡 দেখছো: keyword analyzer পুরো string একটিমাত্র token হিসেবে রাখে।


6️⃣ Professional Tip

  1. Full-text search → standard বা language-specific analyzer

  2. Filter/Exact match → keyword

  3. Special cases → pattern বা custom analyzer


 

 

Powered by Blogger.