elasticsearch-analysis
Assists with log analysis and query construction for Elasticsearch/OpenSearch.
Install
mkdir -p .claude/skills/elasticsearch-analysis && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2893" && unzip -o skill.zip -d .claude/skills/elasticsearch-analysis && rm skill.zipInstalls to .claude/skills/elasticsearch-analysis
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Elasticsearch/OpenSearch log analysis using Lucene query syntax and Query DSL. Use when investigating issues via ELK stack, OpenSearch, or any Elasticsearch-based logging.Key capabilities
- →Extract log statistics and error rates
- →Perform strategic log sampling
- →Cluster log patterns for root cause analysis
- →Construct Lucene syntax queries
- →Build Query DSL JSON aggregations
How it works
The skill mandates a statistics-first workflow using Python scripts to identify patterns before applying Lucene or DSL queries to sample or aggregate specific log data.
Inputs & outputs
When to use elasticsearch-analysis
- →Analyzing system logs for errors
- →Constructing complex log queries
- →Investigating production issues via ELK stack
About this skill
Elasticsearch Analysis
Authentication
IMPORTANT: Credentials are injected automatically by a proxy layer. Do NOT check for ELASTICSEARCH_URL, ES_USER, or ES_PASSWORD in environment variables - they won't be visible to you. Just run the scripts directly; authentication is handled transparently.
MANDATORY: Statistics-First Investigation
NEVER dump raw logs. Always follow this pattern:
STATISTICS → SAMPLE → PATTERNS → CORRELATE
- Statistics First - Know volume, error rate, and top patterns before sampling
- Strategic Sampling - Choose the right strategy based on statistics
- Pattern Extraction - Cluster similar errors to find root causes
- Context Correlation - Investigate around anomaly timestamps
Available Scripts
All scripts are in .claude/skills/observability-elasticsearch/scripts/
PRIMARY INVESTIGATION SCRIPTS
get_statistics.py - ALWAYS START HERE
Comprehensive statistics with pattern extraction.
python .claude/skills/observability-elasticsearch/scripts/get_statistics.py [--index INDEX] [--time-range MINUTES]
# Examples:
python .claude/skills/observability-elasticsearch/scripts/get_statistics.py --time-range 60
python .claude/skills/observability-elasticsearch/scripts/get_statistics.py --index logs-production
Output includes:
- Total count, error count, error rate percentage
- Status distribution (info, warn, error)
- Top services/sources by log volume
- Top error patterns (crucial for quick triage)
- Actionable recommendation
sample_logs.py - Strategic Sampling
Choose the right sampling strategy based on statistics.
python .claude/skills/observability-elasticsearch/scripts/sample_logs.py --strategy STRATEGY [--index INDEX] [--limit N]
# Strategies:
# errors_only - Only error logs (default for incidents)
# warnings_up - Warning and error logs
# around_time - Logs around a specific timestamp
# all - All log levels
# Examples:
python .claude/skills/observability-elasticsearch/scripts/sample_logs.py --strategy errors_only --index logs-production
python .claude/skills/observability-elasticsearch/scripts/sample_logs.py --strategy around_time --timestamp "2026-01-27T05:00:00Z" --window 5
Lucene Query Syntax
Basic Searches
# Simple term
error
# Phrase
"connection refused"
# Field search
level:ERROR
# Wildcard
message:timeout*
# Multiple terms (implicit OR)
error warning
# Required term (AND)
+error +timeout
Field Queries
# Exact match
level:ERROR
# Wildcard
host:web-*
# Range (numeric)
status:[400 TO 599]
# Range (dates)
@timestamp:[2024-01-15T10:00:00 TO 2024-01-15T11:00:00]
# Exists
_exists_:error.stack_trace
Boolean Operators
# AND
error AND timeout
# OR
error OR warning
# NOT
error NOT debug
# Grouping
(error OR warning) AND service:api
Query DSL (JSON)
Match Query
{
"query": {
"match": {
"message": "connection error"
}
}
}
Term Query (Exact Match)
{
"query": {
"term": {
"level": "ERROR"
}
}
}
Bool Query (Compound)
{
"query": {
"bool": {
"must": [
{"term": {"level": "ERROR"}},
{"match": {"message": "timeout"}}
],
"must_not": [
{"term": {"service": "healthcheck"}}
],
"filter": [
{"range": {"@timestamp": {"gte": "now-1h"}}}
]
}
}
}
Aggregations
{
"size": 0,
"aggs": {
"errors_by_service": {
"terms": {
"field": "service.keyword",
"size": 10
}
}
}
}
Investigation Workflow
Standard Incident Investigation
┌─────────────────────────────────────────────────────────────┐
│ 1. STATISTICS FIRST (mandatory) │
│ python get_statistics.py --index <index> │
│ → Know volume, error rate, top patterns │
└─────────────────────────────────────────────────────────────┘
│
▼
High Error Rate?
┌─────────────┴─────────────┐
│ │
YES (>5%) NO
│ │
▼ ▼
┌─────────────────────────────┐ ┌───────────────────────────────────────────┐
│ 2. FAST PATH │ │ 2. TARGETED INVESTIGATION │
│ Sample errors directly │ │ Filter by specific criteria │
│ python sample_logs.py │ │ python sample_logs.py --strategy all │
│ --strategy errors_only │ │ → Look for anomalies │
└─────────────────────────────┘ └───────────────────────────────────────────┘
Quick Commands Reference
| Goal | Command |
|---|---|
| Start investigation | get_statistics.py --index X |
| Sample errors only | sample_logs.py --strategy errors_only --index X |
| Investigate spike | sample_logs.py --strategy around_time --timestamp T |
| All logs | sample_logs.py --strategy all --index X --limit 20 |
Common Aggregation Patterns
Errors Over Time
{
"size": 0,
"query": {"term": {"level": "ERROR"}},
"aggs": {
"errors_over_time": {
"date_histogram": {
"field": "@timestamp",
"fixed_interval": "5m"
}
}
}
}
Top Error Messages
{
"size": 0,
"query": {"term": {"level": "ERROR"}},
"aggs": {
"top_errors": {
"terms": {
"field": "message.keyword",
"size": 10
}
}
}
}
Nested Aggregation (Errors by Service, then by Message)
{
"size": 0,
"aggs": {
"by_service": {
"terms": {"field": "service.keyword", "size": 10},
"aggs": {
"by_message": {
"terms": {"field": "message.keyword", "size": 5}
}
}
}
}
}
Field Types
Keyword vs Text
- keyword: Exact match, aggregatable (
service.keyword) - text: Full-text search, not aggregatable (
message)
// For aggregation, use .keyword suffix
"terms": {"field": "service.keyword"}
// For full-text search, use text field
"match": {"message": "connection error"}
Anti-Patterns to Avoid
- ❌ NEVER skip statistics -
get_statistics.pyis MANDATORY first step - ❌ Unbounded queries - Always specify time ranges and limits
- ❌ Fetching all logs - Use sampling strategies, not unbounded searches
- ❌ Ignoring error rate - High error rate means immediate investigation
- ❌ Text field in aggregation - Use
.keywordsuffix for terms aggs - ❌ Wildcard prefix -
*erroris expensive, prefererror*or exact match
When not to use it
- →Skipping the mandatory statistics-first investigation step
- →Executing unbounded queries without time ranges or limits
- →Using text fields for aggregation instead of .keyword
Prerequisites
Limitations
- →Prefix wildcards like *error are prohibited due to performance costs
- →Aggregations require .keyword fields
How it compares
It enforces a structured investigation sequence rather than allowing ad-hoc, unbounded log searching.
Compared to similar skills
elasticsearch-analysis side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| elasticsearch-analysis (this skill) | 2 | 5mo | Review | Intermediate |
| family-health-analyzer | 1 | 7mo | No flags | Intermediate |
| token-data-sources | 0 | 5mo | No flags | Intermediate |
| dataeng-codebase-analyst | 0 | 3mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by incidentfox
View all by incidentfox →You might also like
family-health-analyzer
huifer
分析家族病史、评估遗传风险、识别家庭健康模式、提供个性化预防建议
token-data-sources
justinchuby
When debugging why the analysis page shows missing or zero token data, or when adding new cost/usage visualizations.
dataeng-codebase-analyst
juankmvanegas
Analyze existing Data Engineering codebase — data pipeline, reproducibility, artifacts, and operational flow
kql
microsoft
KQL language expertise for writing correct, efficient Kusto queries using the Fabric RTI MCP tools. Covers syntax gotchas, join patterns, dynamic types, datetime pitfalls, regex patterns, serialization, memory management, result-size discipline, and advanced functions (geo, vector, graph). USE THIS
data-quality-monitor-designer
nguyenpv1980-wq
Design data-quality monitoring for production pipelines and stores — checks across the six dimensions (freshness, completeness/volume, uniqueness, validity, consistency/referential integrity, distribution drift), placed at the right pipeline stage (ingest, transform, serving), each with severity, an
kql
microsoft
KQL language expertise for writing correct, efficient Kusto Query Language queries. Covers syntax gotchas, join patterns, dynamic types, datetime pitfalls, regex patterns, serialization, memory management, result-size discipline, and advanced functions (geo, vector, graph). USE THIS SKILL whenever w