2. Architecture & Document Structure
Duration45min AI Banned
Introduction
In this workshop, you’ll explore a real-time e-commerce data pipeline where transactions flow from a Python generator through Logstash into Elasticsearch, ready for analysis in Kibana.
Imagine you’re a data engineer at an online retail company. Your mission: understand the data infrastructure and explore the structure of incoming transactions.
By the end of this session, you’ll have mastered:
- Navigating the Elastic Stack architecture
- Understanding how data flows through the pipeline
- Analyzing document structure and field types
Learning Objectives
By completing this workshop, you will be able to:
- ✅ Explore Elasticsearch clusters using both Kibana GUI and command-line APIs
- ✅ Understand the Logstash pipeline and data transformation process
- ✅ Analyze document structure and field organization
- ✅ Identify different data types (objects, arrays, nested structures)
Prerequisites
Prerequisites
Before starting, ensure you have completed Setup & Prerequisites. Your ELK stack should be running and verified.
Section 1: Architecture Discovery
Before diving into data analysis, you need to understand the infrastructure powering your e-commerce platform. In this section, you’ll explore how Elasticsearch, Logstash, and Kibana work together to ingest, store, and visualize data.
Exercise 1.1: Explore the Elastic Stack via Kibana GUI
Kibana provides a web interface for interacting with Elasticsearch. Let’s explore the available tools.
Start the Generator
Before proceeding, start the data generator to populate Elasticsearch with transactions:
|
|
Leave this running in a terminal. You should see: ✓ Connected to Logstash. Keep it running during 3 minutes.
-
Open Kibana in your browser:
http://localhost:5601 -
Navigate to Management → Stack Management → Index Management
- Observe the list of indices
- Note the document counts and storage size
- Identify the index receiving transaction data
-
Open Dev Tools (left sidebar)
- This is where you’ll execute Elasticsearch queries
- The console shows two panels: left (your query), right (response)
-
Try this sample query to see all indices:
1GET /_cat/indices?vClick the ▶️ Play button or press
Ctrl+Enterto execute.
Exercise 1.2: Explore via Command Line
While Kibana is convenient, command-line access is essential for automation and troubleshooting. Elasticsearch provides Cat APIs for human-readable output.
Use the command line to explore the cluster. All Elasticsearch APIs are accessible via HTTP requests.
Useful Documentation:
- Cluster health:
- List indices: Cat Indices API Documentation
- Index statistics: Cat Count API Documentation
- Elasticsearch shards and replicas: A practical guide
Questions
- What is the cluster health status (color)?
- How many nodes are in your cluster?
- How many primary shards does the transaction index have?
- Look at the cluster health output: How many shards are unassigned? Given that you have 2 indices and the number of nodes in your cluster, can you explain why some shards are unassigned and why the cluster status is this color?
Exercise 1.3: Understand the Logstash Pipeline
Logstash processes incoming data before sending it to Elasticsearch. Understanding this pipeline is crucial for troubleshooting data issues.
- Understand the data generator output:
If you have forgot to stop the generator stop it now. Now, let’s examine what data the generator produces by reading its help documentation:
|
|
Read the DATA OUTPUT section carefully. You’ll see examples of both transaction and application logs. Write down one example of a transaction document and one example of an application log entry.
-
Locate the Logstash pipeline configuration:
- Check the
/logstash/pipeline/directory in the workshop repository - Find the configuration files for both data streams:
01-transactions.conf(handles JSON transactions)02-applogs.conf(handles plain text logs)
- Check the
-
Analyze the pipeline stages for BOTH configurations:
For
01-transactions.conf:- Input: What port? What codec?
- Filter: What transformations occur?
- Output: What index does it write to?
For
02-applogs.conf:- Input: What port? What codec? (different from transactions!)
- Filter: What does the GROK pattern do? What about the KV filter?
- Output: What index pattern does it use?
Documentation: Logstash Configuration
Questions
- What are the TWO different data formats sent by the generator? Which port for each?
- Why does the logs pipeline use GROK while the transactions pipeline doesn’t?
- Does Logstash add any fields that weren’t in the original data?
- What Elasticsearch indices do the two pipelines write to?
Production Insight
In real systems, Logstash pipelines often include conditional logic, error handling, and multiple outputs. Understanding the pipeline is essential for debugging data quality issues.
Section 2: Document Structure Analysis
Now that you understand the architecture and data flow, let’s explore the actual structure of documents stored in Elasticsearch. This understanding is crucial before learning to query and analyze the data.
Understanding Elasticsearch Queries
Before diving into exercises, let’s understand the basic structure of an Elasticsearch query:
|
|
We’ll explore more complex queries in the next workshop. For now, we’ll use simple queries to retrieve and examine documents.
Exercise 2.1: Explore Document Response
Let’s start by retrieving a simple document to understand its structure and the response format.
Queries
- Write a query to retrieve one document from the
transactions-*index.
Questions
Once you execute your query, analyze the response structure:
- Which field gives the number of documents that matched the query?
- How long did the query take to execute?
- What is the document’s unique ID?
- What fields are present in the
_sourceobject?
Exercise 2.2: Understanding Elasticsearch Data Structures
Before analyzing the document, let’s understand how Elasticsearch stores different types of data structures:
Single object:
|
|
A single object with properties. Accessible via dot notation: user.id, user.email, user.country, etc.
Array of simple values:
|
|
A list of simple values of the same type. Each value can be queried independently.
Array of objects:
|
|
A list of objects with properties.
Important: Arrays of objects (like products) have special behavior in Elasticsearch. We’ll explore this in detail in later workshops.
Questions
Now, analyze the structure of the document you retrieved from the previous exercise. Look at the _source field in your response, which contains the actual transaction data.
- How many products/items are in this transaction?
- Identify a field that contains a single object (not an array). What is its structure?
- Identify a field that contains an array of objects. What is its structure?
- What fields uniquely identify this transaction?
- Can you find an example of an array of simple values in your document?
- Can you identify any arrays of objects in your document? Which field contains multiple objects with the same structure?