0
0
Elasticsearchquery~30 mins

Visualization types in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a 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".