Skip to main content
PreparationZone Logo
PrepZone

Elasticsearch Aggregations

Bucket and metric aggregations for faceted search and sales dashboards.

Pass checkpoint below

Read these first

Why this matters

  • VaultCommerce faceted browse ("outdoor, $50–$100, 4+ stars") needs category and price histograms without loading every product into the app server.
  • Aggregations on analyzed text fields fail — facet on keyword fields only.
  • Heavy aggregations on high-cardinality fields (SKU) stress data nodes — design dashboards with rollups or separate indices.
Cluster
Node 1Shard 0 primary
Node 2Shard 1 primary
Node 3Shard 0 replica
An index is split into shards across nodes. Replicas provide failover and read scaling.

Metric aggregations

Java
GET /vaultcommerce-products/_search
{
  "size": 0,
  "aggs": {
    "avg_price": { "avg": { "field": "price" } },
    "price_stats": { "stats": { "field": "price" } },
    "categories": { "cardinality": { "field": "category" } }
  }
}

size: 0 returns only aggregation results — standard for dashboard APIs that do not need individual hits.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Bucket aggregations for facets
  • Sub-aggregations
  • Composite pagination for high cardinality

Test yourself

Answer these before moving on — recall is what makes it stick.