Build the mental model
Lesson 11 introduced aggregation basics (metric and bucket), and this project combines several aggregations, nested together, into a single request to build a real analytics dashboard — nesting a `date_histogram` bucket aggregation (time-based buckets, say "how many events occurred per day") inside a `terms` aggregation gets you two-dimensional analytics — "view count per day, per topic" — from a single query, serving the same purpose as SQL's `GROUP BY topic, date_trunc('day', occurred_at)` with two levels of grouping. Kibana was introduced in Lesson 7 as the Dev Tools console, but its core purpose is visualization — instead of manually parsing an Elasticsearch aggregation query's JSON response and drawing a chart yourself, Kibana's "Lens"/"Visualize" UI lets you point at an index pattern and interactively build bar charts, line charts, and data tables via drag-and-drop, with Kibana itself auto-generating the underlying aggregation query. To build a production-grade analytics dashboard, store raw event data (like each user's lesson-view event) in a separate time-series index (applying Lesson 16's ILM concept here) rather than mixing it with the `tutorials` catalog index — analytics data's growth pattern (daily events) and catalog data's growth pattern (occasional edits) are so different that they need separate index and lifecycle strategies.
Connect it to a real scenario
From the Tutorial Platform's `lesson-views` event index (documents shaped `{ tutorialId, tags, occurredAt }`, with a Lesson 16-style ILM policy), write a nested aggregation query for "view count per topic (tags), per week" — nesting a `date_histogram` (weekly interval) inside a `terms` aggregation (on `tags`). Prototype this query in Kibana's Dev Tools first, then switch to Kibana Lens and build a "most-viewed topics this month" bar chart and a "weekly completion trend" line chart with drag-and-drop, pinning them into a dashboard to share with the admin team.
Try the working example
GET /lesson-views/_search
{
"size": 0,
"aggs": {
"by_topic": {
"terms": { "field": "tags", "size": 10 },
"aggs": {
"by_week": {
"date_histogram": { "field": "occurredAt", "calendar_interval": "week" }
}
}
}
}
}You get nested buckets of weekly view counts under each tag — ready to chart in Kibana Lens.5-minute try-it
Write a query for "average views per difficulty level" by nesting an `avg` metric aggregation inside a `terms` (difficulty) aggregation — describe how you would configure the result as a Kibana bar chart.
One important caution
Storing high-volume analytics event data (daily user activity logs) inside the same `tutorials` catalog index — analytics data disrupts the catalog index's size and growth pattern and can hurt search performance too.
Leaving the outer `terms` aggregation's `size` parameter at its default (10) inside a nested aggregation — if topic count exceeds 10, some buckets are silently dropped and the chart's data ends up incomplete.
Kibana Guide — Create a Visualization — Elastic