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

การกรอง ช่วงค่า และบริบทการสืบค้น

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

บทเรียน 4 จาก 413 ขั้นตอน

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

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

Two Contexts

Every clause in Elasticsearch runs in one of two contexts: query context (How well does this match? produces a score) or filter context (Does this match? yes/no, no score).

Why Filters Are Fast

Filters do not compute relevance scores and their results are cached, so repeated filters are very cheap. Use filters whenever you do not need ranking from that clause.

The bool filter Clause

Inside a bool query, the filter array runs in filter context while must runs in query context.

GET /products/_search
{ "query": { "bool": {
  "must":   [ { "match": { "name": "laptop" } } ],
  "filter": [ { "term": { "in_stock": true } } ]
}}}

Range Queries

The range query selects values within bounds using gte, gt, lte, lt. It is commonly placed in filter context.

{ "range": { "price": { "gte": 100, "lte": 500 } } }

Date Ranges

Range works on dates too, including date math like now-7d for relative windows.

{ "range": { "created": { "gte": "now-7d/d" } } }

terms Filter

The terms query matches any of several exact values, like a SQL IN list.

{ "terms": { "category": [ "books", "music" ] } }

exists Filter

The exists query keeps only documents that have a non-null value for a field.

{ "exists": { "field": "discount" } }

Combining Many Filters

Stack multiple filters in the filter array; they are ANDed together and all benefit from caching.

"filter": [
  { "term":  { "in_stock": true } },
  { "range": { "price": { "lte": 1000 } } }
]

must_not for Exclusion

Use must_not inside bool to exclude documents. It also runs in filter context.

"must_not": [ { "term": { "discontinued": true } } ]

Sorting Without Scores

When you rely on filters alone, every document scores the same, so add an explicit sort (for example by price or date) to order results.

"sort": [ { "price": "asc" } ]

Performance Rule of Thumb

Put the scoring text match in must and push every yes/no condition into filter. This keeps scoring focused and lets caching speed up the rest.

Quick Check

When should a clause go in filter context?

Recap

You learned the query vs filter context distinction, used range, terms, and exists filters inside bool, applied must_not for exclusion, and added explicit sorting when relying on filters.

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

เรียนรู้ 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 ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การกรอง ช่วงค่า และบริบทการสืบค้น” ใช้เวลานานแค่ไหน

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

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

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

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

  1. บทนำสู่ Query DSL
  2. การสอบถามแบบ Term และ Match
  3. การรวมการสอบถามด้วย Bool
  4. การกรอง ช่วงค่า และบริบทการสืบค้น
← กลับไปที่ Elasticsearch & Full Text Search Systems