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

การสอบถามแบบคลุมเครือและไวลด์การ์ด

ใช้งานการจับคู่แบบคลุมเครือเพื่อรองรับการพิมพ์ผิด และการสอบถามแบบไวลด์การ์ดสำหรับการค้นหาตามรูปแบบ เพื่อเพิ่มความทนทานต่อข้อผิดพลาดของการค้นหา

บทเรียน 2 จาก 412 ขั้นตอน

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

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

Search Beyond Exact Matches

Imagine searching for 'apple' but typing 'aple'. Traditional exact searches fail! This lesson introduces techniques to make your search more forgiving and powerful.

We'll explore how to handle typos and search for patterns, ensuring users find what they need even with slight inaccuracies.

What is Fuzzy Search?

Fuzzy search helps you find documents that are 'similar' to your search term, even if there are minor spelling mistakes or variations.

It's incredibly useful for:

  • Correcting user typos
  • Matching variations in spelling
  • Improving user experience by being more tolerant

How Fuzziness Works: Levenshtein

Elasticsearch's fuzzy matching is often based on the Levenshtein distance algorithm. This algorithm measures the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other.

For example, the Levenshtein distance between 'apple' and 'aple' is 1 (one deletion). Between 'apple' and 'apply' is 2 (one substitution, one insertion).

Your First Fuzzy Query

You can add fuzziness to a match query. The fuzziness parameter controls the maximum Levenshtein distance allowed.

Try running this example. It will find 'apple' even if you search for 'aple':

GET /products/_search
{
  "query": {
    "match": {
      "name": {
        "query": "aple",
        "fuzziness": "AUTO"
      }
    }
  }
}

Fuzzy Parameters: AUTO & Length

The fuzziness parameter can be set to AUTO (recommended) or a number (0, 1, or 2).

  • AUTO: Elasticsearch calculates the allowed edit distance based on the term's length. Shorter terms allow fewer edits.
  • prefix_length: You can specify a number of initial characters that must exactly match. This can improve performance and relevance.

What are Wildcard Queries?

Wildcard queries allow you to search for patterns within text using special characters. They're useful when you know only part of a term or want to match a family of terms.

Unlike fuzzy queries that correct typos, wildcards help you broaden your search based on specific patterns.

Wildcard Operators

Wildcard queries use two main operators:

  • * (asterisk): Matches zero or more characters. For example, appl* would match 'apple', 'application', 'appliance'.
  • ? (question mark): Matches any single character. For example, appl? would match 'apply' but not 'apple'.

Wildcard in Action

Let's see a wildcard query in practice. This query will find documents where the product_code field starts with 'ABC' and has any characters following it.

Remember, wildcard queries are typically case-sensitive on keyword fields and can be slow on text fields.

GET /products/_search
{
  "query": {
    "wildcard": {
      "product_code": {
        "value": "ABC*"
      }
    }
  }
}

Wildcard Query Cautions

While powerful, wildcard queries, especially those with leading wildcards (e.g., *term), can be computationally expensive and slow.

  • They don't use the inverted index efficiently.
  • They have to scan many terms to find matches.
  • Consider using match_phrase_prefix or completion suggesters for 'autocomplete' type functionality instead.

Fuzzy vs. Wildcard: When to Use

Choosing between fuzzy and wildcard depends on your goal:

  • Fuzzy Queries: Best for handling minor typos and spelling variations. Ideal when you expect a close but not exact match.
  • Wildcard Queries: Best for pattern matching and when you know parts of a term but not the whole thing. Be mindful of performance, especially with leading wildcards.

Test Your Knowledge

Which of the following statements are TRUE regarding fuzzy and wildcard queries in Elasticsearch?

Recap: Flexible Search

You've mastered two powerful techniques for more flexible search:

  • Fuzzy Queries: Leverage the Levenshtein distance to find matches despite typos, using fuzziness (e.g., AUTO).
  • Wildcard Queries: Search for patterns using * (zero or more chars) and ? (single char). Use with caution due to potential performance impacts.

These methods make your search more fault-tolerant and user-friendly!

เริ่มต้นได้ฟรี

เรียนรู้ Elasticsearch & Full Text Search Systems ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

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

บทเรียน “การสอบถามแบบคลุมเครือและไวลด์การ์ด” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “การสอบถามแบบคลุมเครือและไวลด์การ์ด”

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

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

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

บทเรียน “การสอบถามแบบคลุมเครือและไวลด์การ์ด” ใช้เวลานานแค่ไหน

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

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

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

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

  1. การค้นหาวลีและความใกล้เคียง
  2. การสอบถามแบบคลุมเครือและไวลด์การ์ด
  3. การเน้นผลการค้นหา
  4. การรวมผลสำหรับการค้นหาแบบแบ่งหมวด
← กลับไปที่ Elasticsearch & Full Text Search Systems