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

การรวมผลสำหรับการค้นหาแบบแบ่งหมวด

ใช้การรวมผลของ Elasticsearch เพื่อสร้างหมวดตัวกรอง ฮิสโตแกรม และตัวชี้วัดสรุปควบคู่กับผลการค้นหา

บทเรียน 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 บทเรียน

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

Beyond Matching

Search finds documents; aggregations summarize them. They power faceted navigation, dashboards, and analytics, all in the same request as the search.

Two Families

Aggregations come in two main families:

  • Bucket aggregations group documents (e.g. by category)
  • Metric aggregations compute numbers (e.g. average price)

A Terms Facet

The terms aggregation produces a bucket per distinct value with counts, the classic facet.

GET /products/_search
{ "size": 0, "aggs": {
  "by_category": { "terms": { "field": "category" } }
}}

size 0 Trick

Setting size: 0 returns no document hits, only the aggregation results, which is efficient when you only want the facets.

Aggregate on keyword

Aggregations run on non-analyzed fields. Use the keyword field, not the analyzed text field, or you will bucket on individual tokens.

{ "terms": { "field": "brand.keyword" } }

Metric Aggregations

Metrics like avg, min, max, and sum compute a single value over matching documents.

"aggs": { "avg_price": { "avg": { "field": "price" } } }

Histograms

A histogram buckets numeric values into fixed intervals, great for price ranges.

"aggs": { "price_ranges": {
  "histogram": { "field": "price", "interval": 100 }
}}

Date Histograms

A date_histogram groups by calendar intervals like day or month, ideal for time-series charts.

"aggs": { "per_day": { "date_histogram": {
  "field": "created", "calendar_interval": "day"
}}}

Nesting Aggregations

You can nest a metric inside a bucket: average price within each category. Nesting is how rich facets are built.

"aggs": { "by_cat": {
  "terms": { "field": "category" },
  "aggs": { "avg_price": { "avg": { "field": "price" } } }
}}

Facets Respect the Query

Aggregations are computed over the documents that match the query and filters, so facet counts naturally reflect the current search context.

Cardinality for Distinct Counts

The cardinality metric gives an approximate distinct-value count, far cheaper than exact counting on large data.

"aggs": { "unique_brands": {
  "cardinality": { "field": "brand.keyword" } } }

Quick Check

Why aggregate on a keyword field instead of a text field?

Recap

You learned aggregations for faceted search: bucket aggregations like terms and histograms, metric aggregations like avg and cardinality, nesting metrics inside buckets, the size: 0 trick, and why facets use keyword fields.

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

เรียนรู้ 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 เพื่อสร้างหมวดตัวกรอง ฮิสโตแกรม และตัวชี้วัดสรุปควบคู่กับผลการค้นหา คุณปฏิบัติ 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. การค้นหาวลีและความใกล้เคียง
  2. การสอบถามแบบคลุมเครือและไวลด์การ์ด
  3. การเน้นผลการค้นหา
  4. การรวมผลสำหรับการค้นหาแบบแบ่งหมวด
← กลับไปที่ Elasticsearch & Full Text Search Systems