with one click
elasticsearch-analysis
// Elasticsearch/OpenSearch log analysis using Lucene query syntax and Query DSL. Use when investigating issues via ELK stack, OpenSearch, or any Elasticsearch-based logging.
// Elasticsearch/OpenSearch log analysis using Lucene query syntax and Query DSL. Use when investigating issues via ELK stack, OpenSearch, or any Elasticsearch-based logging.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | elasticsearch-analysis |
| description | Elasticsearch/OpenSearch log analysis using Lucene query syntax and Query DSL. Use when investigating issues via ELK stack, OpenSearch, or any Elasticsearch-based logging. |
| allowed-tools | Bash(python *) |
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.
NEVER dump raw logs. Always follow this pattern:
STATISTICS ā SAMPLE ā PATTERNS ā CORRELATE
All scripts are in .claude/skills/observability-elasticsearch/scripts/
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:
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
# Simple term
error
# Phrase
"connection refused"
# Field search
level:ERROR
# Wildcard
message:timeout*
# Multiple terms (implicit OR)
error warning
# Required term (AND)
+error +timeout
# 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
# AND
error AND timeout
# OR
error OR warning
# NOT
error NOT debug
# Grouping
(error OR warning) AND service:api
{
"query": {
"match": {
"message": "connection error"
}
}
}
{
"query": {
"term": {
"level": "ERROR"
}
}
}
{
"query": {
"bool": {
"must": [
{"term": {"level": "ERROR"}},
{"match": {"message": "timeout"}}
],
"must_not": [
{"term": {"service": "healthcheck"}}
],
"filter": [
{"range": {"@timestamp": {"gte": "now-1h"}}}
]
}
}
}
{
"size": 0,
"aggs": {
"errors_by_service": {
"terms": {
"field": "service.keyword",
"size": 10
}
}
}
}
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā 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 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| 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 |
{
"size": 0,
"query": {"term": {"level": "ERROR"}},
"aggs": {
"errors_over_time": {
"date_histogram": {
"field": "@timestamp",
"fixed_interval": "5m"
}
}
}
}
{
"size": 0,
"query": {"term": {"level": "ERROR"}},
"aggs": {
"top_errors": {
"terms": {
"field": "message.keyword",
"size": 10
}
}
}
}
{
"size": 0,
"aggs": {
"by_service": {
"terms": {"field": "service.keyword", "size": 10},
"aggs": {
"by_message": {
"terms": {"field": "message.keyword", "size": 5}
}
}
}
}
}
service.keyword)message)// For aggregation, use .keyword suffix
"terms": {"field": "service.keyword"}
// For full-text search, use text field
"match": {"message": "connection error"}
get_statistics.py is MANDATORY first step.keyword suffix for terms aggs*error is expensive, prefer error* or exact match