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:

1
2
cd elasticsearch-workshop/generators/
uv run python generator.py

Leave this running in a terminal. You should see: ✓ Connected to Logstash. Keep it running during 3 minutes.

  1. Open Kibana in your browser: http://localhost:5601

  2. 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
  3. Open Dev Tools (left sidebar)

    • This is where you’ll execute Elasticsearch queries
    • The console shows two panels: left (your query), right (response)
  4. Try this sample query to see all indices:

    1
    
    GET /_cat/indices?v

    Click the ▶️ Play button or press Ctrl+Enter to execute.

Hint: Understanding the GET keyword

Elasticsearch uses a RESTful API architecture. Every query is an HTTP request:

  • GET: Retrieve data (read operation)
  • POST: Send/create data
  • PUT: Create or update
  • DELETE: Remove data

The Dev Tools console is a convenient interface for sending HTTP requests to Elasticsearch. Behind the scenes, GET /_cat/indices?v is equivalent to:

1
curl -X GET "http://localhost:9200/_cat/indices?v"

We’ll explore HTTP requests directly in the next exercise.

Learn more: Elasticsearch REST APIs

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:

Hint: How to make HTTP requests to Elasticsearch

Elasticsearch listens on http://localhost:9200. You can use curl:

1
curl http://localhost:9200/_cat/health?v

The ?v parameter adds column headers for readability.

Questions
  1. What is the cluster health status (color)?
  2. How many nodes are in your cluster?
  3. How many primary shards does the transaction index have?
  4. 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.

  1. 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:

1
2
cd elasticsearch-workshop/generators/
uv run python generator.py --help

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.

  1. 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)
  2. 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

Hint: Understanding Logstash filters

Logstash filters transform data between input and output. Common filters:

  • json: Parse JSON strings into structured data
  • mutate: Add/remove/rename fields
  • date: Parse timestamp strings into date objects
  • grok: Extract structured data from unstructured text

Look for these filter types in the configuration.

Questions
  1. What are the TWO different data formats sent by the generator? Which port for each?
  2. Why does the logs pipeline use GROK while the transactions pipeline doesn’t?
  3. Does Logstash add any fields that weren’t in the original data?
  4. 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:

1
2
3
4
5
6
7
GET /index-pattern/_search
{
  "size": 10,                           // Number of documents to return (default: 10)
  "query": {
    "match_all": {}                     // Simple query to match all documents
  }
}

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
  1. Write a query to retrieve one document from the transactions-* index.
Hint: How to retrieve a single document

Use a basic match_all query with the size parameter to limit the results to 1 document.

Questions

Once you execute your query, analyze the response structure:

  1. Which field gives the number of documents that matched the query?
  2. How long did the query take to execute?
  3. What is the document’s unique ID?
  4. What fields are present in the _source object?

Exercise 2.2: Understanding Elasticsearch Data Structures

Before analyzing the document, let’s understand how Elasticsearch stores different types of data structures:

Single object:

1
2
3
4
5
"user": {
  "id": "U123",
  "email": "user@example.com",
  "country": "France"
}

A single object with properties. Accessible via dot notation: user.id, user.email, user.country, etc.

Array of simple values:

1
"tags": ["important", "verified", "priority"]

A list of simple values of the same type. Each value can be queried independently.

Array of objects:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
"items": [
  {
    "id": "ITEM-001",
    "name": "Widget A",
    "type": "electronics",
    "price": 99.99
  },
  {
    "id": "ITEM-002",
    "name": "Gadget B",
    "type": "accessories",
    "price": 24.50
  }
]

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.

  1. How many products/items are in this transaction?
  2. Identify a field that contains a single object (not an array). What is its structure?
  3. Identify a field that contains an array of objects. What is its structure?
  4. What fields uniquely identify this transaction?
  5. Can you find an example of an array of simple values in your document?
  6. Can you identify any arrays of objects in your document? Which field contains multiple objects with the same structure?