0Pricing
Elasticsearch & Full Text Search Systems · บทเรียน

การแมปและประเภทข้อมูลพื้นฐาน

ทำความรู้จักแนวคิดการแมป วิธีที่ Elasticsearch อนุมานประเภทข้อมูล และวิธีกำหนดการแมปอย่างชัดเจนแบบง่ายสำหรับฟิลด์ของคุณ

การแมปและประเภทข้อมูลพื้นฐาน เป็นบทเรียน Elasticsearch & Full Text Search Systems ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Elasticsearch & Full Text Search Systems และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Mapping: Your Data's Blueprint

When you put data into Elasticsearch, it needs to understand what kind of data each piece is. This is where mapping comes in.

Mapping is like a schema that defines the fields in your documents and their data types, such as text, numbers, or dates.

Why Mapping Matters

Think of mapping as a blueprint for your search engine. It tells Elasticsearch:

  • How to store each field
  • How to index (prepare for search) each field
  • How each field can be searched and analyzed

Without proper mapping, your searches might not work as expected!

Dynamic Mapping: Elasticsearch's Guess

Elasticsearch is smart! If you index a document without defining a mapping first, it tries to guess the data type for each field. This is called dynamic mapping.

It's convenient for quick starts, but not always ideal for precise control over your data.

Dynamic Mapping Example

Let's see dynamic mapping in action. We'll index a document into a new index called my_books. Elasticsearch will automatically create the index and guess the field types.

PUT /my_books/_doc/1
{
  "title": "The Art of Search",
  "author": "Jane Doe",
  "published_year": 2023,
  "is_available": true,
  "pages": 320
}

Inspecting Dynamic Mappings

After indexing, we can retrieve the automatically generated mapping for my_books to see what data types Elasticsearch inferred for each field.

You'll see types like text, keyword, long, and boolean.

GET /my_books/_mapping

Limitations of Dynamic Mapping

While handy, dynamic mapping has limits. For example, Elasticsearch might map a city name as text (for full-text search) when you really need it as a keyword (for exact filtering).

This can lead to inefficient searches or unexpected results. That's why explicit mapping is crucial.

Defining Explicit Mappings

Explicit mapping means you define the schema yourself before indexing documents. This gives you full control over how your data is stored and indexed.

You define mappings when you create an index, inside the mappings object, under properties.

PUT /my_custom_index
{
  "mappings": {
    "properties": {
      "field_name": { "type": "data_type" }
    }
  }
}

Common Data Types: Text & Keyword

Two fundamental types are text and keyword:

  • text: Used for full-text search (e.g., book descriptions). Text is analyzed, broken into words, and processed.
  • keyword: Used for exact value matching, filtering, and sorting (e.g., product IDs, tags). Keywords are stored as-is.

Explicit Mapping Example: Text & Keyword

Here’s how you'd explicitly map a product_name for search and a product_id for exact filtering.

Notice how we create the index with the mapping before adding any documents.

PUT /products_v1
{
  "mappings": {
    "properties": {
      "product_name": { "type": "text" },
      "product_id": { "type": "keyword" }
    }
  }
}

Quick Check: Choosing Data Types

You're building an Elasticsearch index for an e-commerce platform. Which data types would be most appropriate for the following fields to enable efficient searching and filtering?

Recap: Mastering Your Data's Structure

Great job! You've learned the basics of Elasticsearch mapping.

  • Mapping defines the structure and types of your document fields.
  • Dynamic mapping is Elasticsearch's auto-guessing feature.
  • Explicit mapping gives you full control, letting you define types like text (for search) and keyword (for exact matches), and numeric types like integer and float.

Controlling your mappings is key to powerful and accurate search!

คำถามที่พบบ่อย

บทเรียน “การแมปและประเภทข้อมูลพื้นฐาน” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การแมปและประเภทข้อมูลพื้นฐาน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Elasticsearch & Full Text Search Systems ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การแมปและประเภทข้อมูลพื้นฐาน”

ทำความรู้จักแนวคิดการแมป วิธีที่ Elasticsearch อนุมานประเภทข้อมูล และวิธีกำหนดการแมปอย่างชัดเจนแบบง่ายสำหรับฟิลด์ของคุณ คุณปฏิบัติ Elasticsearch & Full Text Search Systems ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Elasticsearch & Full Text Search Systems หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Elasticsearch & Full Text Search Systems บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การแมปและประเภทข้อมูลพื้นฐาน” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Elasticsearch & Full Text Search Systems นี้ได้ไหม

ได้ บทเรียน Elasticsearch & Full Text Search Systems ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การทำดัชนีเอกสารใน Elasticsearch
  2. การดำเนินการ CRUD กับเอกสาร
  3. การแมปและประเภทข้อมูลพื้นฐาน
  4. การสร้างดัชนีจำนวนมากและ Bulk API
← กลับไปที่ Elasticsearch & Full Text Search Systems