Elasticsearch & Full Text Search Systems · درس

التجميعات المتداخلة والتجميعات الفرعية

تعلّم دمج التجميعات عبر تداخل المقاييس داخل الحاويات، وبناء تحليلات متعددة المستويات، والتنقل في بنى المستندات المتداخلة باستخدام التجميعة المتداخلة.

الدرس 4 من 413 خطوة

التجميعات المتداخلة والتجميعات الفرعية درس مجاني في Elasticsearch & Full Text Search Systems على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Elasticsearch & Full Text Search Systems، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Elasticsearch & Full Text Search Systems 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Combining Aggregations

A single aggregation answers one question. Real analytics often need layered answers: average price per category, or top brands per region. Elasticsearch lets you nest aggregations inside one another.

This lesson shows how to compose them.

The aggs Hierarchy

Any bucket aggregation can contain a sub-aggs block. The sub-aggregation runs once per bucket, operating only on the documents in that bucket.

This is the core mechanism for multi-dimensional analytics.

Metric Inside a Bucket

Here we group documents by category, then compute the average price within each group. The metric aggregation lives inside the bucket aggregation's aggs.

GET sales/_search
{
  "size": 0,
  "aggs": {
    "by_category": {
      "terms": { "field": "category" },
      "aggs": {
        "avg_price": { "avg": { "field": "price" } }
      }
    }
  }
}

Reading the Result

Each bucket in by_category now carries an avg_price value alongside its doc_count. You get the category name, how many docs it holds, and its average price in one response.

Bucket Inside a Bucket

You can nest bucket aggregations too. Group by region, then by brand within each region. This produces a two-level breakdown.

"aggs": {
  "by_region": {
    "terms": { "field": "region" },
    "aggs": {
      "by_brand": { "terms": { "field": "brand" } }
    }
  }
}

Mind the Cardinality

Deeply nested terms aggregations can explode combinatorially. A region with 50 brands across 20 regions yields up to 1,000 buckets. Use the size parameter to limit returned buckets and protect memory.

Multiple Sub-Aggregations

A bucket can hold several sub-aggregations at once. Here each category reports both its average and maximum price.

"by_category": {
  "terms": { "field": "category" },
  "aggs": {
    "avg_price": { "avg": { "field": "price" } },
    "max_price": { "max": { "field": "price" } }
  }
}

The nested Aggregation

When data uses the nested field type, you must enter that scope with a nested aggregation before aggregating on its inner fields. It points at a path.

"aggs": {
  "variants": {
    "nested": { "path": "variants" },
    "aggs": {
      "avg_qty": { "avg": { "field": "variants.quantity" } }
    }
  }
}

Reverse Nested

Inside a nested aggregation you can jump back to the parent document scope using reverse_nested. This lets you count distinct parent docs that contain a matching nested element.

"reverse_nested": {},
"aggs": {
  "parent_count": { "value_count": { "field": "_id" } }
}

Sorting Buckets by a Metric

Order parent buckets by a nested sub-metric using order. Here categories are sorted by their average price, descending.

"terms": {
  "field": "category",
  "order": { "avg_price": "desc" }
}

Design Tips

Keep nesting shallow when possible, always set size on inner terms, and put the most selective bucket aggregation first to reduce the work done by deeper levels.

Quick Check

Test your grasp of sub-aggregations.

Recap

You learned to compose aggregations:

  • Any bucket aggregation can hold sub-aggs that run per bucket.
  • Nest metrics in buckets, or buckets in buckets for multi-level breakdowns.
  • Use the nested and reverse_nested aggregations to traverse nested document scopes.
  • Control bucket explosion with size and order buckets by sub-metrics with order.
البدء مجانًا

تعلم Elasticsearch & Full Text Search Systems مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «التجميعات المتداخلة والتجميعات الفرعية» مجاني؟

نعم — نص درس «التجميعات المتداخلة والتجميعات الفرعية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Elasticsearch & Full Text Search Systems، انتقل إلى CoddyKit PRO. تتضمن دورة Elasticsearch & Full Text Search Systems 4 دروس في المجموع.

ماذا ستتعلم في «التجميعات المتداخلة والتجميعات الفرعية»؟

تعلّم دمج التجميعات عبر تداخل المقاييس داخل الحاويات، وبناء تحليلات متعددة المستويات، والتنقل في بنى المستندات المتداخلة باستخدام التجميعة المتداخلة. تتمرن على Elasticsearch & Full Text Search Systems مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. التجميعات المعيارية
  2. تجميعات الحاويات
  3. تجميعات مسارات المعالجة
  4. التجميعات المتداخلة والتجميعات الفرعية
← العودة إلى Elasticsearch & Full Text Search Systems