0
0
Elasticsearchquery~30 mins

Lens for drag-and-drop analysis in Elasticsearch - Mini Project: Build & Apply

Choose your learning style9 modes available
Lens for drag-and-drop analysis
📖 Scenario: You work as a data analyst using Elasticsearch. You want to create a simple Lens visualization that lets you drag and drop fields to analyze sales data easily.
🎯 Goal: Build a Lens configuration JSON that defines a drag-and-drop analysis for sales data, showing total sales by product category.
📋 What You'll Learn
Create a base index pattern for sales data
Add a configuration for a metric to sum sales amounts
Add a configuration for a bucket to group by product category
Output the final Lens configuration JSON
💡 Why This Matters
🌍 Real World
Elasticsearch Lens helps analysts quickly explore and visualize data by dragging and dropping fields without writing complex queries.
💼 Career
Data analysts and engineers use Lens configurations to build dashboards and reports that help businesses understand trends and make decisions.
Progress0 / 4 steps
1
Create the base index pattern
Create a variable called indexPattern and set it to the string "sales-data" representing the Elasticsearch index pattern.
Elasticsearch
Need a hint?

The index pattern is the name of the Elasticsearch index you want to analyze.

2
Add metric configuration for total sales
Create a dictionary called metric with keys operationType set to "sum" and field set to "sales_amount" to sum the sales amounts.
Elasticsearch
Need a hint?

The metric defines what calculation Lens will do on the sales_amount field.

3
Add bucket configuration for product category
Create a dictionary called bucket with keys operationType set to "terms" and field set to "product_category" to group data by product category.
Elasticsearch
Need a hint?

The bucket groups the data by product category for the Lens visualization.

4
Create and print the Lens configuration JSON
Create a dictionary called lensConfig with keys indexPattern, metric, and bucket using the variables you created. Then print lensConfig.
Elasticsearch
Need a hint?

The final Lens configuration combines all parts and shows the JSON structure.