ELK Stack — Kibana Fundamentals Exercises
Kibana Fundamentals Exercises
These exercises reinforce the concepts covered in this chapter — Discover, KQL/Lucene queries, visualizations, dashboards, and Lens. Work through them sequentially, as each exercise builds on skills from the previous ones.
Prerequisites
Before starting, ensure you have:
- Elasticsearch running with sample data. If you haven’t loaded sample data yet, go to Kibana Home and click Try sample data → Sample web logs.
- Kibana accessible at
http://localhost:5601. - Alternatively, if you have your own log data (from Filebeat or Logstash), you can adapt these exercises to your indices.
Exercise 1: Exploring Data with Discover
Difficulty: ⭐ Beginner
Scenario
You’re a new member of the operations team. Your first task is to familiarize yourself with the log data available in Kibana by creating data views and exploring data in Discover.
Requirements
- Create a data view named
Web Logsthat matches thekibana_sample_data_logsindex, usingtimestampas the time field. - Open Discover with this data view and set the time range to Last 7 days.
- Add the following columns to the document table:
clientip,response,request,machine.os. - Find all documents where the response code is
404. - Save the search as
404 Errors - Web Logs. - Use the Field statistics tab to identify which
machine.osvalue generates the most traffic. - Find a 404 error document and view its surrounding documents.
Show Solution
Step 1: Create the data view
- Open Kibana → Menu (☰) → Analytics → Discover.
- Click the data view dropdown → Create a data view.
- Name:
Web Logs. - Index pattern:
kibana_sample_data_logs. - Timestamp field:
timestamp. - Click Save data view to Kibana.
Step 2: Set time range and add columns
- In Discover, make sure
Web Logsis selected as the data view. - Click the time picker (top-right) → select Last 7 days → click Apply.
- In the field browser (left sidebar), find
clientipand click the + button to add it as a column. - Repeat for
response,request, andmachine.os. - You should now see a table with these four columns plus the timestamp.
Step 3: Filter for 404 errors
- In the query bar, type:
response: 404 - Press Enter or click Update.
- The document table now shows only documents with a 404 response code.
Step 4: Save the search
- Click Save in the top toolbar.
- Name:
404 Errors - Web Logs. - Click Save.
Step 5: Field statistics
- Clear the query bar (remove
response: 404) and press Enter. - Click the Field statistics tab.
- Find
machine.os— it shows a distribution bar with the top values and their percentages. - The OS with the highest percentage is the one generating the most traffic.
Step 6: Surrounding documents
- Go back to the Documents tab.
- Add the filter back:
response: 404. - Click the > expand arrow on any 404 document.
- Click View surrounding documents.
- You can see what requests happened before and after the 404, which helps understand the user’s journey.
Exercise 2: Writing KQL and Lucene Queries
Difficulty: ⭐⭐ Intermediate
Scenario
The security team has asked you to investigate suspicious traffic patterns. You need to write queries to find specific log entries in the web logs data.
Requirements
- Using KQL, find all requests from IP addresses starting with
176.that resulted in a503response. - Using KQL, find all
GETrequests to URLs containing/kibanawhere the response time (bytes) is greater than 5000. - Using KQL, find all documents where the
geo.destfield is eitherCNorINand the response is not200. - Switch to Lucene and find all documents where the
urlfield contains a path with “elasticsearch” (use a fuzzy match to also catch typos like “elasticsarch”). - Using Lucene, find documents where “error” and “memory” appear within 3 words of each other in the
messagefield. - Save a query named
Suspicious 503sfor the query from requirement 1.
Show Solution
Requirement 1: KQL — 503 responses from 176.* IPs
- Make sure the query language selector shows KQL.
- Enter the query:
clientip: 176.* and response: 503
- Press Enter. The results show all 503 errors from IP addresses starting with 176.
Requirement 2: KQL — GET requests to /kibana with large responses
request: *kibana* and bytes > 5000
Note: The sample data uses bytes for response size. If your data has a method field, you can add method: "GET".
Requirement 3: KQL — Traffic from CN or IN with non-200 responses
(geo.dest: "CN" or geo.dest: "IN") and not response: 200
Requirement 4: Lucene — Fuzzy match for “elasticsearch”
- Click the KQL button in the query bar → select Lucene.
- Enter the query:
url:elasticsearch~2
This uses fuzzy matching with an edit distance of 2, catching variations like “elasticsarch” or “elasticserch”.
Requirement 5: Lucene — Proximity search
message:"error memory"~3
This finds documents where “error” and “memory” appear within 3 words of each other.
Note: The sample web logs may not have a message field with these terms. If you’re using your own application logs, this works well. With sample data, try:
url:"elasticsearch kibana"~5
Requirement 6: Save a query
- Switch back to KQL and enter:
clientip: 176.* and response: 503 - Click the bookmark icon (💾) next to the query bar.
- Click Save current query.
- Name:
Suspicious 503s. - Check Include filters and Include time range if desired.
- Click Save.
Exercise 3: Building Visualizations
Difficulty: ⭐⭐ Intermediate
Scenario
The product team wants a set of visualizations to understand web traffic patterns. Create the following visualizations using the Visualize Library (aggregation-based editor).
Requirements
- Create a Line chart showing the total number of requests over time (Date Histogram on
timestamp, 3-hour interval). - Create a Vertical Bar chart showing the top 10 most requested URLs (
requestfield). - Create a Pie chart showing the distribution of HTTP response codes.
- Create a Data Table showing request count by country (
geo.src), sorted by count descending, limited to top 15. - Create a Gauge visualization showing the average bytes transferred. Set color ranges: Green (0–5000), Yellow (5000–10000), Red (10000–20000).
- Save all visualizations with the naming pattern:
[Web Logs] Description — Chart Type.
Show Solution
Visualization 1: Line chart — Request Rate Over Time
- Menu → Visualize Library → Create visualization → Line.
- Data view:
kibana_sample_data_logs. - Metrics (Y-axis): Count (default).
- Buckets → Add → X-axis:
- Aggregation: Date Histogram.
- Field:
timestamp. - Minimum interval:
3h.
- Click Update (▶).
- Save as:
[Web Logs] Request Rate Over Time — Line.
Visualization 2: Bar chart — Top 10 URLs
- Create visualization → Vertical Bar.
- Metrics: Count.
- Buckets → Add → X-axis:
- Aggregation: Terms.
- Field:
request.keyword. - Size:
10. - Order by: Count descending.
- Click Update.
- Save as:
[Web Logs] Top 10 URLs — Bar.
Visualization 3: Pie chart — Response Code Distribution
- Create visualization → Pie.
- Metrics: Count (Slice size).
- Buckets → Add → Split Slices:
- Aggregation: Terms.
- Field:
response.keyword. - Size:
10.
- Click Update.
- Save as:
[Web Logs] Response Code Distribution — Pie.
Visualization 4: Data Table — Requests by Country
- Create visualization → Data Table.
- Metrics: Count.
- Buckets → Add → Split Rows:
- Aggregation: Terms.
- Field:
geo.src. - Size:
15. - Order by: Count descending.
- Click Update.
- Save as:
[Web Logs] Requests by Country — Table.
Visualization 5: Gauge — Avg Bytes
- Create visualization → Gauge.
- Metrics: Average on field
bytes. - Under Options → Ranges:
- 0 to 5000 (Green).
- 5000 to 10000 (Yellow).
- 10000 to 20000 (Red).
- Click Update.
- Save as:
[Web Logs] Avg Bytes Transferred — Gauge.
Exercise 4: Creating a Dashboard
Difficulty: ⭐⭐⭐ Advanced
Scenario
Build a comprehensive web traffic monitoring dashboard using the visualizations created in Exercise 3 and the saved search from Exercise 1.
Requirements
- Create a new dashboard named
Web Traffic Monitoring. - Add a Markdown panel at the top with the dashboard title, description, and last updated date.
- Add Controls — an Options List dropdown for
geo.src(source country) and another forresponse(status code). - Add all five visualizations from Exercise 3.
- Add the saved search
404 Errors - Web Logsfrom Exercise 1. - Arrange the panels in a logical layout:
- Row 1: Markdown header (full width).
- Row 2: Controls (full width).
- Row 3: Request Rate (line) and Response Code Distribution (pie) — side by side.
- Row 4: Top URLs (bar) and Requests by Country (table) — side by side.
- Row 5: Avg Bytes gauge (1/3 width) — centered.
- Row 6: 404 Errors saved search (full width).
- Set the dashboard time range to Last 7 days and enable auto-refresh every 30 seconds.
- Save the dashboard.
Show Solution
Step 1: Create the dashboard
- Menu → Analytics → Dashboard → Create dashboard.
Step 2: Add Markdown header
- Click Add panel → Create visualization.
- Choose Markdown (legacy) or Text.
- Enter:
## Web Traffic Monitoring Dashboard
**Data Source:** Kibana Sample Web Logs
**Owner:** Operations Team
**Updated:** 2026-04-01
---
- Click Save and return.
- Drag the panel to the top and stretch it to full width.
Step 3: Add Controls
- Click Add panel → Controls.
- Click Add control:
- Data view:
Web Logs(orkibana_sample_data_logs). - Field:
geo.src. - Type: Options List.
- Data view:
- Click Add control again:
- Field:
response. - Type: Options List.
- Field:
- Click Save and return.
- Position the controls panel below the header.
Step 4: Add visualizations
- Click Add panel → Add from library.
- Search for
[Web Logs]to find all five visualizations. - Click each one to add it:
[Web Logs] Request Rate Over Time — Line[Web Logs] Response Code Distribution — Pie[Web Logs] Top 10 URLs — Bar[Web Logs] Requests by Country — Table[Web Logs] Avg Bytes Transferred — Gauge
Step 5: Add saved search
- Click Add panel → Add from library.
- Search for
404 Errors - Web Logs. - Click to add it.
Step 6: Arrange panels
- Drag and resize panels:
- Line chart and Pie chart side by side (each ~50% width).
- Bar chart and Table side by side (each ~50% width).
- Gauge centered, smaller width (~33%).
- Saved search panel full width at the bottom.
Step 7: Set time range and auto-refresh
- Click the time picker → select Last 7 days.
- Click the auto-refresh clock icon → set interval to 30 seconds → click Start.
Step 8: Save the dashboard
- Click Save.
- Name:
Web Traffic Monitoring. - Click Save.
Exercise 5: Building a Lens Visualization
Difficulty: ⭐⭐⭐ Advanced
Scenario
The engineering manager wants a single Lens visualization that shows the error rate percentage over time, broken down by operating system. The error rate is defined as: (count of responses >= 400) / (total count) × 100.
Requirements
- Open Lens from the Visualize Library.
- Select the
kibana_sample_data_logsdata view (or yourWeb Logsdata view). - Set the time range to Last 7 days.
- Create a Line chart with:
- Horizontal axis:
timestampwith an auto interval. - Vertical axis: a formula that calculates error rate percentage.
- Break down by:
machine.os.keyword(top 5).
- Horizontal axis:
- The formula should be:
count(kql='response >= 400') / count() * 100. - Format the vertical axis as a percentage (or include “%” in the label).
- Save the visualization as
[Web Logs] Error Rate by OS Over Time — Lens Line. - Add this visualization to the
Web Traffic Monitoringdashboard. - Create a runtime field called
response_categorythat categorizes responses:- 200–299 → “2xx Success”
- 300–399 → “3xx Redirect”
- 400–499 → “4xx Client Error”
- 500–599 → “5xx Server Error”
- Create a Donut chart using the runtime field showing the distribution of response categories. Save it as
[Web Logs] Response Categories — Lens Donut.
Show Solution
Steps 1–2: Open Lens
- Menu → Visualize Library → Create visualization → Lens.
- Data view:
kibana_sample_data_logs(orWeb Logs). - Time picker: Last 7 days.
Steps 3–6: Create the error rate line chart
- The chart type selector should show Line (click it to switch if needed).
- Drag
timestampto the Horizontal axis zone. - Click the Vertical axis zone.
- In the configuration panel, switch from a simple aggregation to Formula.
- Enter the formula:
count(kql='response >= 400') / count() * 100
- Set the label to:
Error Rate (%). - Under format, choose Number and set decimal places to 2.
- Close the metric config.
- Drag
machine.os.keywordto the Break down by zone.- Set the number of values to 5.
- The chart now shows error rate percentage over time, with a separate line for each OS.
Step 7: Save the visualization
- Click Save → name:
[Web Logs] Error Rate by OS Over Time — Lens Line. - Click Save.
Step 8: Add to dashboard
- Open the
Web Traffic Monitoringdashboard. - Click Edit to enter edit mode.
- Click Add panel → Add from library.
- Search for
[Web Logs] Error Rate by OS Over Time — Lens Line. - Click to add it. Position it in the layout.
- Click Save to save the dashboard.
Step 9: Create a runtime field
- Go back to Lens → Create visualization.
- In the field list (left sidebar), click Create field.
- Name:
response_category. - Type: Keyword.
- Script:
def code = doc['response.keyword'].value;
if (code == '200' || code == '201' || code == '204') {
emit('2xx Success');
} else if (code == '301' || code == '302' || code == '304') {
emit('3xx Redirect');
} else if (code == '404' || code == '403' || code == '400') {
emit('4xx Client Error');
} else if (code == '500' || code == '502' || code == '503') {
emit('5xx Server Error');
} else {
emit('Other');
}
Note: Depending on your data, you may need to handle the field as a number rather than a keyword. If response is a numeric field:
def code = (int)doc['response'].value;
if (code >= 200 && code < 300) {
emit('2xx Success');
} else if (code >= 300 && code < 400) {
emit('3xx Redirect');
} else if (code >= 400 && code < 500) {
emit('4xx Client Error');
} else if (code >= 500 && code < 600) {
emit('5xx Server Error');
} else {
emit('Other');
}
- Click Save.
Step 10: Create the donut chart
- Click the chart type selector → choose Donut.
- Drag the new
response_categoryfield to the Slice by zone. - The donut chart shows the distribution of 2xx, 3xx, 4xx, and 5xx responses.
- Save as:
[Web Logs] Response Categories — Lens Donut.
Summary
After completing these exercises, you can:
- Create data views and explore data interactively in Discover.
- Write KQL and Lucene queries for precise filtering.
- Build various visualization types — line, bar, pie, table, gauge, metric.
- Assemble visualizations into interactive dashboards with controls and filters.
- Use Lens to quickly build visualizations with formulas and runtime fields.
Back to: Kibana Fundamentals — Chapter overview and navigation.