Search basics
index=prod sourcetype=app:json service=checkout level=ERROR earliest=-1h
index=prod "timeout" NOT healthcheck
index=prod status>=500 | head 20Filter as early as possible (index, sourcetype, time) for fast searches.
Core commands
| Command | Does |
|---|---|
stats count, avg(x) by field | aggregate |
timechart span=5m count by status | time series |
top limit=10 field / rare field | most/least common |
table a b c / fields - _raw | choose columns |
sort -count | sort descending |
dedup field | unique values |
eval new=expr | compute field |
where x > 5 | filter with expressions |
rex field=_raw "id=(?<id>\d+)" | regex extract |
spath | parse JSON fields |
transaction trace_id maxspan=5m | group events (expensive) |
lookup users.csv id OUTPUT name | enrich |
Recipes
Error rate per service
index=prod sourcetype=app:json
| stats count AS total, count(eval(status>=500)) AS errors by service
| eval error_rate=round(errors/total*100, 2)
| sort -error_rateP95 latency over time
index=prod service=checkout | timechart span=5m perc95(duration_ms) AS p95Compare before/after deploy
index=prod service=checkout
| eval phase=if(_time < strptime("2025-06-01 14:00", "%Y-%m-%d %H:%M"), "before", "after")
| stats avg(duration_ms) perc95(duration_ms) count(eval(level="ERROR")) by phaseFollow one request
index=prod trace_id=4bf92f3577b34da6 | sort _time | table _time service level messageTop error messages
index=prod level=ERROR | stats count by message | sort -count | head 10eval functions
| eval sec=round(ms/1000, 2)
| eval tier=case(ms<100,"fast", ms<500,"ok", true(),"slow")
| eval host=lower(host), short=substr(id, 1, 8)
| eval ok=if(status<400, 1, 0)
| eval t=strftime(_time, "%H:%M")Alerts & dashboards
- Saved search + trigger condition (e.g.
errors > 50in 5 min) → email/Slack/PagerDuty. - Throttle to avoid alert storms.
- Dashboards: panels from searches; use tokens for env/service dropdowns.
- Summary indexing / data models /
tstatsfor fast large-scale reports.