0Pricing
Elasticsearch & Full Text Search Systems · Lesson

Aggregations for Faceted Search

Use Elasticsearch aggregations to build facets, histograms, and summary metrics alongside search results.

Aggregations for Faceted Search is a free Elasticsearch & Full Text Search Systems lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Elasticsearch & Full Text Search Systems learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Beyond Matching

Search finds documents; aggregations summarize them. They power faceted navigation, dashboards, and analytics, all in the same request as the search.

Two Families

Aggregations come in two main families:

  • Bucket aggregations group documents (e.g. by category)
  • Metric aggregations compute numbers (e.g. average price)

A Terms Facet

The terms aggregation produces a bucket per distinct value with counts, the classic facet.

GET /products/_search
{ "size": 0, "aggs": {
  "by_category": { "terms": { "field": "category" } }
}}

size 0 Trick

Setting size: 0 returns no document hits, only the aggregation results, which is efficient when you only want the facets.

Aggregate on keyword

Aggregations run on non-analyzed fields. Use the keyword field, not the analyzed text field, or you will bucket on individual tokens.

{ "terms": { "field": "brand.keyword" } }

Metric Aggregations

Metrics like avg, min, max, and sum compute a single value over matching documents.

"aggs": { "avg_price": { "avg": { "field": "price" } } }

Histograms

A histogram buckets numeric values into fixed intervals, great for price ranges.

"aggs": { "price_ranges": {
  "histogram": { "field": "price", "interval": 100 }
}}

Date Histograms

A date_histogram groups by calendar intervals like day or month, ideal for time-series charts.

"aggs": { "per_day": { "date_histogram": {
  "field": "created", "calendar_interval": "day"
}}}

Nesting Aggregations

You can nest a metric inside a bucket: average price within each category. Nesting is how rich facets are built.

"aggs": { "by_cat": {
  "terms": { "field": "category" },
  "aggs": { "avg_price": { "avg": { "field": "price" } } }
}}

Facets Respect the Query

Aggregations are computed over the documents that match the query and filters, so facet counts naturally reflect the current search context.

Cardinality for Distinct Counts

The cardinality metric gives an approximate distinct-value count, far cheaper than exact counting on large data.

"aggs": { "unique_brands": {
  "cardinality": { "field": "brand.keyword" } } }

Quick Check

Why aggregate on a keyword field instead of a text field?

Recap

You learned aggregations for faceted search: bucket aggregations like terms and histograms, metric aggregations like avg and cardinality, nesting metrics inside buckets, the size: 0 trick, and why facets use keyword fields.

Frequently asked questions

Is the “Aggregations for Faceted Search” lesson free?

Yes — the full text of “Aggregations for Faceted Search” is free to read here on the web, and the Elasticsearch & Full Text Search Systems course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Elasticsearch & Full Text Search Systems course, upgrade to CoddyKit PRO.

What will I learn in “Aggregations for Faceted Search”?

Use Elasticsearch aggregations to build facets, histograms, and summary metrics alongside search results. You practise Elasticsearch & Full Text Search Systems with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Elasticsearch & Full Text Search Systems?

No prior experience is required. Elasticsearch & Full Text Search Systems on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Aggregations for Faceted Search” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Elasticsearch & Full Text Search Systems lesson?

Yes. Every Elasticsearch & Full Text Search Systems lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Phrase and Proximity Searches
  2. Fuzzy and Wildcard Queries
  3. Highlighting Search Results
  4. Aggregations for Faceted Search
← Back to Elasticsearch & Full Text Search Systems