Getting started
Introduction
Splunk searches machine data with SPL. This reference covers the search commands, statistics, field extraction, and lookups you reach for most.
- SPL search reference (help.splunk.com)
- Search tutorial (help.splunk.com)
- SPL for SQL users (help.splunk.com)
Basic searches
index=web sourcetype=access_combined status=404
index=web (status=404 OR status=503) host=web*
index=web user=* NOT status=200
index=web "Failed password"
index and sourcetype narrow the data. AND is implied between terms;
write AND, OR, and NOT in uppercase.
See: search command
Time ranges
index=web earliest=-24h latest=now
index=web earliest=-7d@d
index=web earliest=-1mon@mon latest=@mon
index=web earliest=11/01/2026:00:00:00
Units are s, m, h, d, w, mon, q, y. @ snaps down to a
boundary: @d, @h, or @w0 for Sunday.
Relative earliest should be paired with latest=now.
See: time modifiers
Subsearches
index=web [search index=threats | return src]
index=web [search index=threats | fields src | format]
The inner search runs first. return passes back field values; format
builds an OR list. Subsearches stop at 10,000 results or 60 seconds.
See: about subsearches
tstats and data models
Filtering
Fields and table
Sorting results
| Command | Result |
|---|---|
| sort host | Ascending |
| sort -host | Descending |
| sort 100 host | Keep first 100 |
| sort 0 host | Keep all results |
| sort num(bytes), host | Numeric, then text |
| sort ip(clientip) | Sort as IP addresses |
sort defaults to 10,000 results. Separate multiple fields with commas.
See: sort
Removing duplicates
| Command | Result |
|---|---|
| dedup host | One event per host |
| dedup source host | One per pair |
| dedup 3 source | Three per source |
| dedup host sortby -_time | Keep the newest |
| dedup host keepempty=true | Keep missing-field events |
dedup keeps events in search order. Field names are space-separated.
See: dedup
head and tail
| Command | Result |
|---|---|
| head 5 | First five events |
| head | First ten events |
| head (status=200) | Until the expression fails |
| head (status=200) keeplast=true | Include the failing event |
| tail 5 | Last five events |
| tail | Last ten events |
head stops as soon as it has enough results, so it is cheap.
See: head
where
| Command | Result |
|---|---|
| where bytes > 1000 | Numeric comparison |
| where status >= 400 AND status < 500 | Boolean filter |
| where isnull(user) | Field is missing |
| where like(path, "/api/%") | SQL-style match |
| where match(path, "^/api/") | Regex match |
| where cidrmatch("10.0.0.0/8", ip) | CIDR match |
where evaluates an eval expression for each result and can call eval
functions. * is multiplication there, not a wildcard.
See: where
Reporting
stats
| Command | Result |
|---|---|
| stats count | Count events |
| stats count(status) | Count non-null status |
| stats dc(host) | Distinct hosts |
| stats avg(bytes) by host | Average per host |
| stats sum(bytes) AS total by host | Sum renamed |
| stats count by host | Events per host |
| stats count(eval(status=404)) AS not_found | Count matches |
Without by, stats returns one row. count(field) counts events where
the field is present; count counts all events.
See: stats
eventstats and streamstats
| eventstats avg(bytes) AS avg_bytes by host
| eval delta = bytes - avg_bytes
| streamstats window=10 avg(bytes) AS avg_10
| streamstats current=f last(status) AS previous_status
eventstats adds the group aggregate to every event. streamstats adds a
running aggregate up to each event; current=f ignores the current event.
See: eventstats, streamstats
Aggregation functions
Counts
| Function | Result |
|---|---|
count | Number of events |
count(x) | Events where x is non-null |
dc(x) | Distinct values |
estdc(x) | Approximate distinct count |
Numeric
| Function | Result |
|---|---|
sum(x) | Total |
avg(x) | Mean |
min(x), max(x) | Bounds |
median(x) | Middle value |
mode(x) | Most frequent |
stdev(x) | Standard deviation |
var(x) | Sample variance |
range(x) | Max minus min |
Percentiles
| Function | Result |
|---|---|
perc5(x) | 5th percentile |
perc95(x) | 95th percentile |
exactperc95(x) | Exact percentile |
upperperc95(x) | Approximate upper bound |
Values
| Function | Result |
|---|---|
first(x) | First value in event order |
last(x) | Last value in event order |
list(x) | All values, input order |
values(x) | Distinct values, sorted |
perc<N> takes a number from 1 to 99. Use earliest and latest when
order by time matters, not first and last.
See: aggregate functions
top and rare
| Command | Result |
|---|---|
| top url | Ten most common URLs |
| top 20 url | Twenty most common |
| top user by host | Top user per host |
| top user, host | Common pairs |
| rare url | Ten least common URLs |
| rare 5 user by host | Least common per host |
Both add count and percent fields and return 10 results by default.
Field lists are comma-separated.
transaction
| transaction clientip maxspan=30m maxpause=5m
| transaction user startswith="login" endswith="logout"
Groups related events into one result and adds duration and eventcount.
maxpause starts a new transaction after a gap.
See: transaction
Charting
chart and timechart
Rate functions
| Function | Result |
|---|---|
per_second(x) | Per-second rate |
per_minute(x) | Per-minute rate |
per_hour(x) | Per-hour rate |
per_day(x) | Per-day rate |
These are timechart aggregators only. They scale the sum of x to the
span, so per_hour(x) stays per-hour on a 5m chart.
See: timechart
bin
| Command | Result |
|---|---|
| bin _time span=1h | Hourly buckets |
| bin bytes span=1000 | Fixed-width buckets |
| bin latency bins=20 | About 20 buckets |
bin is called by chart and timechart; use it directly with stats.
See: bin
Fields
eval
| eval kbps = bytes / 1024
| eval status_class = if(status >= 500, "error", "ok")
| eval level = case(code=1, "low", code=2, "med", true(), "high")
| eval user = coalesce(username, "anonymous")
eval creates or overwrites fields. Separate expressions with commas;
later expressions see earlier ones.
See: eval
Renaming fields
| Command | Result |
|---|---|
| rename src AS client_ip | Rename a field |
| rename src AS client_ip, dest AS target | Rename two fields |
| rename user* AS account* | Rename with wildcards |
Renames fields without changing their values. Commas separate the pairs.
See: rename
String and value functions
| eval parts = split(path, "/")
| eval first = mvindex(parts, 1)
| eval name = lower(coalesce(user, "unknown"))
Functions
| Function | Result |
|---|---|
if(cond, a, b) | Choose one value |
case(cond, a, ...) | First true condition |
coalesce(a, b) | First non-null |
len(x) | String length |
lower(x), upper(x) | Change case |
split(x, ",") | Split into multivalue |
mvindex(mv, 0) | Pick one value |
mvcount(mv) | Count values |
if and case return values; split and mvindex work on multivalue
fields.
See: eval functions
rex
| rex "user=(?<user>\w+)"
| rex field=path "^/api/(?<version>v\d+)/"
| rex max_match=0 "tag=(?<tags>\w+)"
Named capture groups become fields. The default input is _raw;
max_match=0 collects every match into a multivalue field.
See: rex
spath
| spath
| spath path=user.name
| spath input=payload path=items{}.sku output=sku
Extracts JSON or XML fields. Without path, it auto-extracts all fields
from the first 5,000 characters.
See: spath
convert and time
| eval when = strftime(_time, "%Y-%m-%d %H:%M")
| eval epoch = strptime("2026-11-15", "%Y-%m-%d")
| convert ctime(_time) AS human
| eval age = now() - _time
strftime formats time, strptime parses it, and now() is the search
time. convert rewrites fields in place.
See: convert
Lookups
lookup
| Command | Result |
|---|---|
| lookup dnslookup host | Add all matching fields |
| lookup dnslookup host OUTPUT ip | Add only ip |
| lookup dnslookup host AS server OUTPUT ip AS server_ip | Rename on match |
| lookup geo.csv ip | Use a CSV file |
Fields match by name unless renamed with AS. OUTPUT adds only the
listed fields; OUTPUTNEW skips fields that already exist.
See: lookup
inputlookup and outputlookup
| Command | Result |
|---|---|
| inputlookup users.csv | Read a lookup table |
| inputlookup users.csv where active=1 | Filter lookup rows |
| outputlookup users.csv | Overwrite the table |
| outputlookup users.csv append=true | Append rows |
| outputlookup users_kv key_field=username | Update KV store rows |
inputlookup reads a CSV or KV store table without searching an index.
outputlookup writes lookup tables and is treated as a risky command.
key_field updates KV store collections, not CSV files.
See: inputlookup, outputlookup
Pitfalls
Quoting and wildcards
| Command | Result |
|---|---|
host=web* | Wildcard match |
host="web*" | Quoted wildcard, same match |
| where host="web*" | Literal asterisk |
| where like(host, "web%") | Wildcard in where |
"Failed password" | Phrase match |
Boolean operators must be uppercase. Double-quote values with spaces; single quotes only appear around field names in eval expressions.
Missing fields
| Command | Result |
|---|---|
user=* | Field exists |
NOT user=* | Field is missing |
NOT status=200 | Includes missing status |
status!=200 | Requires status |
field=* tests existence. != drops results where the field is missing;
NOT field=value keeps them.
0 Comments for this cheatsheet. Write yours!