🗓️ 15052024 1438

ELASTICSEARCH AGGREGATIONS
  • Summary of data

Categories​

CategoryDescription
Metric aggregationscalculate metrics from field values (e.g. sum, average)
Bucket aggregationsgroup documents into buckets (bins) based on certain criterias
Pipeline aggregationstake input from other aggregations

Bucket aggregations​

  • Create buckets of documents
    • each bucket is associated with a criterion
  • can hold sub-aggregations
{
"size": 0,
"query": {
"bool": {
"must": [
{
"terms": {
"orderSource": ["source1", "source2"] // Adjust as needed
}
},
{
"range": {
"orderDate": {
"gte": "now-30d/d", // Adjust date range
"lte": "now/d"
}
}
}
]
}
},
"aggs": {
"orderSum": {
"sum": {
"field": "orderAmount" // Adjust to your field name
}
},
"orderStatusCounts": {
"terms": {
"field": "orderStatus",
"size": 10 // Adjust as needed
},
"aggs": {
"statusCount": {
"value_count": {
"field": "orderStatus"
}
}
}
}
}
}

References​