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

การรวมข้อมูลแบบบักเก็ต

จัดกลุ่มเอกสารลงใน “บักเก็ต” ตามฟิลด์ เช่น คำ ช่วง หรือวันที่ เพื่อรองรับการค้นหาแบบแบ่งหมวดหมู่และการจัดประเภทข้อมูล

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

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

Grouping Your Data with Buckets

Welcome to Bucket Aggregations! In Elasticsearch, aggregations allow you to analyze your data.

Bucket aggregations specifically group documents into sets, or 'buckets', based on field values. Think of it like the GROUP BY clause in SQL.

  • Categorize data: Group products by brand.
  • Faceted search: Show counts for different filters.
  • Analyze trends: See activity per day or month.

Finding Unique Values with Terms

The terms aggregation is one of the most common bucket aggregations. It finds the top unique values for a specific field and then counts how many documents fall into each unique value's bucket.

It's incredibly useful for seeing the distribution of categorical data, like product categories, user roles, or country names.

Example: Products by Category

Let's use a terms aggregation to find the top 5 product categories and the count of products in each. We use .keyword for exact matches on text fields.

GET /products/_search
{
  "size": 0,
  "aggs": {
    "top_categories": {
      "terms": {
        "field": "category.keyword",
        "size": 5
      }
    }
  }
}

Bucketing by Numeric Ranges

The range aggregation allows you to define custom ranges for numeric or date fields. Documents whose field values fall within a defined range are grouped into that bucket.

This is perfect for creating price tiers (e.g., $0-10, $10-50, $50+) or age groups (e.g., 0-18, 19-65, 65+).

Example: Products by Price Range

Here, we define three price ranges: products under $10, between $10 and $50, and over $50. The size: 0 means we only want aggregation results, not actual search hits.

GET /products/_search
{
  "size": 0,
  "aggs": {
    "price_tiers": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 10.00 },
          { "from": 10.00, "to": 50.00 },
          { "from": 50.00 }
        ]
      }
    }
  }
}

Grouping Data Over Time

When working with time-series data, the date_histogram aggregation is your best friend. It buckets documents into fixed time intervals like minutes, hours, days, or months.

You specify an interval (e.g., 'day', 'month') and Elasticsearch automatically creates buckets for each period, even if no documents exist for a particular period.

Example: Sales Trends by Month

This aggregation groups sales orders by month, allowing you to easily track monthly sales performance. We assume an order_date field of type date.

GET /sales/_search
{
  "size": 0,
  "aggs": {
    "monthly_sales": {
      "date_histogram": {
        "field": "order_date",
        "calendar_interval": "month"
      }
    }
  }
}

Multi-Level Grouping: Nesting Buckets

The true power of bucket aggregations comes from nesting them. You can place one bucket aggregation inside another to create hierarchical groupings.

For example, you might want to see product categories, and then within each category, the price ranges of products. This enables deep, multi-dimensional analysis.

Where Buckets Shine

Bucket aggregations are fundamental for many real-world applications:

  • Faceted Search: Allowing users to filter search results by category, brand, price range, etc.
  • Data Exploration: Discovering patterns and distributions in your data.
  • Dashboards: Building visualizations like bar charts (e.g., sales per month, products per category).
  • Reporting: Generating summary reports based on grouped data.

Bucket Aggregation Quiz

You are analyzing user feedback and want to count how many reviews were submitted each day over the past week. Which aggregation type is most suitable?

Bucket Aggregations Recap

Great job! You've learned about the power of Bucket Aggregations in Elasticsearch.

  • They group documents into logical 'buckets'.
  • terms: Groups by unique field values.
  • range: Groups by custom numeric or date ranges.
  • date_histogram: Groups by fixed time intervals.
  • You can nest them for multi-level analysis.

Next, we'll explore Metric Aggregations, which perform calculations (like sum, avg, min, max) on the data within these buckets!

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

บทเรียน “การรวมข้อมูลแบบบักเก็ต” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การรวมข้อมูลแบบบักเก็ต” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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