Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Create Basic Visualizations in Elasticsearch
📖 Scenario: You are working as a data analyst for an online store. You want to create simple visualizations to understand sales data better using Elasticsearch queries.
🎯 Goal: Build Elasticsearch queries step-by-step to create data for three common visualization types: bar chart, pie chart, and line chart.
📋 What You'll Learn
Create an Elasticsearch index called sales_data with sample sales documents
Define a date range filter variable called date_range
Write an aggregation query for a bar chart showing total sales per product category
Write an aggregation query for a pie chart showing sales distribution by region
Write an aggregation query for a line chart showing daily sales over time
💡 Why This Matters
🌍 Real World
Creating visualizations from sales data helps businesses understand trends and make decisions.
💼 Career
Data analysts and developers use Elasticsearch aggregations to prepare data for dashboards and reports.
Progress0 / 4 steps
1
Create the sales_data index with sample documents
Create an Elasticsearch index called sales_data with these exact documents: one with product_category as "Books", region as "North", sales as 100, and date as "2024-06-01"; another with product_category as "Electronics", region as "South", sales as 200, and date as "2024-06-02".
Elasticsearch
Hint
Use the PUT method to add documents to the sales_data index with the exact fields and values.
2
Define a date_range filter for June 2024
Create a variable called date_range that filters documents with date between "2024-06-01" and "2024-06-30".
Elasticsearch
Hint
Use a range query on the date field with gte and lte for the start and end dates.
3
Write a bar chart aggregation query for total sales per product category
Write an Elasticsearch aggregation query called sales_per_category that sums sales grouped by product_category, applying the date_range filter.
Elasticsearch
Hint
Use a filter aggregation with the date_range, then a terms aggregation on product_category.keyword, and inside it a sum aggregation on sales.
4
Add pie chart and line chart aggregation queries
Add two more aggregation queries: sales_by_region for a pie chart that sums sales grouped by region, and daily_sales for a line chart that sums sales grouped by date, both applying the date_range filter.
Elasticsearch
Hint
Use the same filter with date_range for both queries. For sales_by_region, use a terms aggregation on region.keyword. For daily_sales, use a date_histogram aggregation on date with calendar_interval set to "day".
Practice
(1/5)
1. Which visualization type is best to show how parts make up a whole in Elasticsearch dashboards?
easy
A. Bar chart
B. Line chart
C. Pie chart
D. Data table
Solution
Step 1: Understand visualization purpose
Pie charts are designed to show parts of a whole by dividing a circle into slices.
Step 2: Match visualization to data type
Since the question asks for parts of a whole, pie chart fits best over line or bar charts which show trends or comparisons.
Final Answer:
Pie chart -> Option C
Quick Check:
Parts of whole = Pie chart [OK]
Hint: Parts of whole? Think pie chart slices [OK]
Common Mistakes:
Choosing bar chart for parts of whole
Confusing line chart with pie chart
Using data table instead of visual chart
2. Which of the following is the correct Elasticsearch aggregation type to use for a bar chart showing counts per category?
easy
A. terms aggregation
B. date_histogram aggregation
C. avg aggregation
D. max aggregation
Solution
Step 1: Identify aggregation for categories
Terms aggregation groups data by unique values, perfect for categories.
Step 2: Match aggregation to bar chart data
Bar charts often show counts per category, so terms aggregation is correct.
Final Answer:
terms aggregation -> Option A
Quick Check:
Category counts = terms aggregation [OK]
Hint: Use terms aggregation for category counts [OK]
Common Mistakes:
Using avg or max aggregation for counts
Choosing date_histogram for non-date data
Confusing aggregation types
3. Given this Elasticsearch aggregation result for a line chart showing sales over time:
A. A line rising from 10 to 15 between Jan 1 and Jan 2
B. A flat line at 10 for both days
C. A line dropping from 15 to 10 between Jan 1 and Jan 2
D. No line because data format is incorrect
Solution
Step 1: Read aggregation buckets
The buckets show counts 10 on Jan 1 and 15 on Jan 2.
Step 2: Interpret line chart trend
The line chart plots these points over time, so it rises from 10 to 15.
Final Answer:
A line rising from 10 to 15 between Jan 1 and Jan 2 -> Option A
Quick Check:
Counts increase over time = rising line [OK]
Hint: Line chart shows trend from low to high values [OK]
Common Mistakes:
Assuming flat line despite different counts
Thinking data format is invalid
Reversing the trend direction
4. You created a pie chart in Kibana but it shows only one slice with 100% instead of multiple categories. What is the most likely cause?
medium
A. The date range filter is too wide
B. The aggregation used is a single metric, not a terms aggregation
C. The pie chart visualization is not supported in Kibana
D. The data has no documents
Solution
Step 1: Understand pie chart data needs
Pie charts require terms aggregation to split data into categories.
Step 2: Identify cause of single slice
If a single metric aggregation is used, it returns one value, so pie chart shows one slice.
Final Answer:
The aggregation used is a single metric, not a terms aggregation -> Option B
Quick Check:
Single slice = single metric aggregation [OK]
Hint: Use terms aggregation for multiple pie slices [OK]
Common Mistakes:
Blaming Kibana for unsupported visualization
Assuming no data causes single slice
Thinking date range affects slice count
5. You want to create a dashboard showing monthly sales trends and category sales distribution side by side. Which combination of visualization types and aggregations should you use?
hard
A. Bar chart with avg aggregation for trends, data table with max aggregation for categories
B. Data table with sum aggregation for trends, bar chart with avg aggregation for categories
C. Pie chart with date_histogram aggregation for trends, line chart with terms aggregation for categories
D. Line chart with date_histogram aggregation for trends, pie chart with terms aggregation for categories
Solution
Step 1: Choose visualization for monthly trends
Line chart is best for showing trends over time; date_histogram groups data by month.
Step 2: Choose visualization for category distribution
Pie chart shows parts of whole; terms aggregation groups by category.
Final Answer:
Line chart with date_histogram aggregation for trends, pie chart with terms aggregation for categories -> Option D
Quick Check:
Trends = line + date_histogram; categories = pie + terms [OK]
Hint: Trends = line + date_histogram; parts = pie + terms [OK]
Common Mistakes:
Mixing pie chart with date_histogram aggregation
Using avg or max aggregation for category grouping