التجميعات المعيارية
أجرِ حسابات مثل المجموع والمتوسط والحد الأدنى والحد الأقصى والعدد على بياناتك باستخدام أنواع مختلفة من التجميعات المعيارية.
التجميعات المعيارية درس مجاني في Elasticsearch & Full Text Search Systems على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Elasticsearch & Full Text Search Systems، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Elasticsearch & Full Text Search Systems 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Discover Data Insights
What if you could ask "how much total sales did we have last month?" or "what's the average price of our products?" Aggregations in Elasticsearch let you do exactly that!
They provide powerful analytical capabilities beyond simple search. Think of them as SQL's GROUP BY and aggregate functions, but for your search data.
Unpacking Metric Aggregations
Metric aggregations are the simplest type of aggregation. They calculate a single metric (like a sum, average, min, or max) over a set of documents.
They give you numerical summaries of your data, helping you quickly understand key statistics and trends without retrieving all individual documents.
Indexing Sample Sales Data
To demonstrate metric aggregations, let's index some sample sales data. We'll use documents with a price field.
Run this curl command to add our first product:
curl -X PUT "localhost:9200/sales_data/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"product": "Laptop",
"price": 1200,
"quantity": 1
}'Adding More Sample Data
Great! To have more data for our aggregations, let's add two more products. Imagine you've run similar curl commands for these:
sales_data/_doc/2:{"product": "Mouse", "price": 25, "quantity": 2}sales_data/_doc/3:{"product": "Keyboard", "price": 75, "quantity": 1}
Now we have a small dataset to work with!
Calculating the Average (`avg`)
The avg aggregation calculates the arithmetic mean of a numeric field. It's perfect for finding the average price of products, average age, or average score.
Let's find the average price of our indexed products:
curl -X GET "localhost:9200/sales_data/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"average_price": {
"avg": {
"field": "price"
}
}
}
}'Summing Up Values (`sum`)
The sum aggregation calculates the total sum of a numeric field's values. This is ideal for finding total sales, total quantity, or total revenue.
Let's calculate the total price of all indexed products:
curl -X GET "localhost:9200/sales_data/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"total_price": {
"sum": {
"field": "price"
}
}
}
}'Finding Min and Max (`min`, `max`)
The min and max aggregations return the smallest and largest values of a numeric field, respectively. They help identify outliers or boundary values in your data.
Let's find the cheapest and most expensive product prices:
curl -X GET "localhost:9200/sales_data/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"min_price": { "min": { "field": "price" } },
"max_price": { "max": { "field": "price" } }
}
}'Counting Values (`value_count`)
The value_count aggregation counts the number of documents that have a value for a specific field. It's different from a document count because it only considers documents where the field exists and is not null.
Let's count how many products have a 'price' field:
curl -X GET "localhost:9200/sales_data/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"price_count": {
"value_count": {
"field": "price"
}
}
}
}'All Stats in One Go (`stats`)
The stats aggregation is a convenience aggregation that computes min, max, sum, avg, and count (of values) all at once for a numeric field.
It saves you from writing five separate aggregations and is great for a quick overview!
curl -X GET "localhost:9200/sales_data/_search?pretty" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"price_stats": {
"stats": {
"field": "price"
}
}
}
}'Metric Aggregation Check
Consider a scenario where you have a list of product prices: 100, 50, 200, 50, null.
What would be the result of a value_count aggregation on the 'price' field?
Metric Aggregations Recap
In this lesson, you've learned about Elasticsearch metric aggregations, powerful tools for summarizing your data:
avg: Calculates the arithmetic mean.sum: Computes the total sum.min&max: Finds the smallest and largest values.value_count: Counts non-null field values.stats: A convenient way to get all basic stats at once.
These aggregations are fundamental for understanding the numerical characteristics of your data and are often combined for more complex analysis.
الأسئلة الشائعة
هل درس «التجميعات المعيارية» مجاني؟
نعم — نص درس «التجميعات المعيارية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «التجميعات المعيارية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Elasticsearch & Full Text Search Systems هذا؟
نعم. كل درس في Elasticsearch & Full Text Search Systems يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.