← Back to Presentations

Kibana Cheatsheet

Mastering KQL and Visualization for Operational Intelligence

1. KQL Fundamentals

Kibana Query Language (KQL) is the default language for searching and filtering in Kibana. It is designed to be intuitive and provides auto-completion.

KQL Rapid Reference

OperatorKQL SyntaxExample / Use Case
Exact Matchfield : "value"status : "error"
Partial Matchfield : valuemessage : timeout (finds "connection timeout")
Wildcardfield : value*service : api-*
Boolean ANDA AND Bstatus : "error" AND service : "auth"
Boolean ORA OR Bservice : "auth" OR service : "gateway"
Boolean NOTNOT ANOT status : "success"
Existencefield : *userId : * (finds any doc with a userId)
Rangefield > valueresponse_time > 500

Complex Grouping

# Nested logic to isolate a specific failure mode across critical paths
status: "error" AND (service: "payment-gateway" OR service: "auth-provider") AND NOT (cluster: "staging")

2. Operational Analysis Patterns

Beyond simple searches, these patterns help you identify "The Why" behind operational anomalies.

Pattern A: The "Noisy Neighbor"

Identify which service is flooding the logs, potentially masking other errors.

NOT status: "success"

Tip: Use a "Top Values" visualization on the service.name field to see the distribution.

Pattern B: The "Slow Leak"

Finding requests that are just barely crossing the threshold over time.

response_time > 800 AND response_time < 1200

Tip: Use a Line Chart with a constant line at 1000ms to visualize the trend.

Correlation Logic

When an error spikes, use the "Compare Fields" approach:

  • Temporal Correlation: Does the error spike match a deployment timestamp?
  • Dimensional Correlation: Is the error localized to one specific pod_id or availability_zone?
  • Value Correlation: Do all errors share the same request_id or correlation_id?

3. Advanced Filtering

Moving beyond simple KQL into complex filtering within the Discover tab and Lens.

Filtering by Field Types

Field TypeOptimal Query PatternExample
textUse match queries for analyzed fieldsmessage: "connection timeout"
keywordUse exact match for IDs, status, and tagsuserId: "user_123"
numberUse range queries for thresholdscpu_usage > 80
dateRange filtering on timestamps @timestamp < "2024-01-01"

The Power of "KQL vs Lucene"

KQL (Modern)

Autocompletion, simpler syntax, highly integrated with Kibana's UI. Best for 95% of everyday search and filter operations.

Lucene (Legacy/Advanced)

Required for complex logic that KQL cannot handle (e.g. specific regex or proximity searches). Must be toggled in the UI.

4. Dashboard & Visualization

Turning raw logs into actionable insights using Lens and and Dashboard management.

Best Practices for High-Impact Dashboards

  • Hierarchical Layout: Start with "Big Number" metrics (KPIs) at the top, followed by time-series trends, and finally detailed tables at the bottom.
  • Dynamic Filtering: Use Dashboard Filters and Controls (Input fields) to allow viewers to slice data by environment, service, or region.
  • Color Semanticity: Use red for errors/criticals and green for healthy signals. Avoid a "rainbow" of colors that distracts the user.
  • Latency Awareness: Reduce the number of visualizations on a single dashboard to avoid slow loading times (Max 10-12 per page).

Visualization Types vs Use-Cases

VisualizationBest ForTip
MetricSingle KPI (e.g. Error Count)Use for "at a glance" status
Line ChartTrends over time (e.g. Latency)Avoid too many series (max 5-7)
Pie/DonutComposition (e.g. error by service)Only for few categories (< 5)
Data TableDetailed auditing and drill-downLimit columns to essential IDs
HeatmapIdentifying patterns across dimensionsGreat for seeing "off-peak" spikes

5. The Observability Workflow

Observability is not just about search; it is about the journey from a symptom to a root cause.

The "Golden Path" to Root Cause

1. MetricSymptom detected (e.g. p99 Spike)
2. DashboardScope the problem (e.g. Region X)
3. TraceIsolate a specific failed request
4. LogRead the Exception/Stacktrace

In Kibana, this is achieved through Context Switching. When viewing a Trace in APM, you can click "View Logs" to jump immediately to the specific log entries that share the same trace.id, bypassing the need to search manually.

6. Runtime Fields & Scripting

Runtime fields allow you to create new fields at query time without re-indexing the data. This is a game-changer for legacy logs.

Painless Scripting for Custom Fields

// Example: Extracting a version number from a log message
// Field: app_version (Runtime field)

if (doc.containsKey('message') && !doc['message'].empty) {
  String msg = doc['message'].value;
  int start = msg.indexOf('version=');
  if (start != -1) {
    int end = msg.indexOf(' ', start + 8);
    emit(msg.substring(start + 8, end == -1 ? msg.length() : end));
  }
}

When to use Runtime vs Index-time fields?

Runtime Fields (On-the-fly)

Low storage cost, highly flexible. Perfect for prototyping a new filter or handling a field that changes format often.

Index-time Fields (Static)

High performance, supports full indexing. Necessary for large datasets where query speed is critical.

7. Pitfalls & Optimization

Common mistakes that lead to slow dashboards or misleading results.

DANGER: Aggregating on fields with high cardinality (e.g. UserIDs, OrderIDs, a raw TraceID) will consume massive RAM and can crash your Kibana/Elasticsearch nodes.

Solution: Use a "Top N" approach or filter the data down significantly before attempting to visualize a high-cardinality field.

Performance Tuning Tips

  • Filter Early: Always apply a time filter and a basic status filter first. Reducing the dataset before visualization is the #1 performance win.
  • Optimize Interval: Avoid using "Auto" interval on huge time ranges. Set it specifically (e.g. 1h, 1d) to avoid too many buckets.
  • Avoid Wildcards at Start: Queries starting with `*` (e.g. `*error`) are extremely expensive as they force a full index scan. Always start with a prefix if possible.

Need expert help with your ELK Stack implementation?

Book a Strategic Discovery Session