Getting started

Introduction

Splunk searches machine data with SPL. This reference covers the search commands, statistics, field extraction, and lookups you reach for most.

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

| tstats count where index=_internal by sourcetype
| tstats summariesonly=true count from datamodel=Web
| from datamodel:Authentication

tstats queries indexed fields and accelerated summaries, so it is much faster than stats over raw events. from reads a data model directly.

See: tstats, from

Filtering

Fields and table

CommandResult
| fields host, statusKeep two fields
| fields - _rawRemove a field
| fields err*Keep matching fields
| table host, statusOutput columns in order
| table _time, host, statusAdd a column

fields is cheap, so filter early. table sets the output columns and their order.

See: fields, table

Sorting results

CommandResult
| sort hostAscending
| sort -hostDescending
| sort 100 hostKeep first 100
| sort 0 hostKeep all results
| sort num(bytes), hostNumeric, then text
| sort ip(clientip)Sort as IP addresses

sort defaults to 10,000 results. Separate multiple fields with commas.

See: sort

Removing duplicates

CommandResult
| dedup hostOne event per host
| dedup source hostOne per pair
| dedup 3 sourceThree per source
| dedup host sortby -_timeKeep the newest
| dedup host keepempty=trueKeep missing-field events

dedup keeps events in search order. Field names are space-separated.

See: dedup

head and tail

CommandResult
| head 5First five events
| headFirst ten events
| head (status=200)Until the expression fails
| head (status=200) keeplast=trueInclude the failing event
| tail 5Last five events
| tailLast ten events

head stops as soon as it has enough results, so it is cheap.

See: head

where

CommandResult
| where bytes > 1000Numeric comparison
| where status >= 400 AND status < 500Boolean 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

CommandResult
| stats countCount events
| stats count(status)Count non-null status
| stats dc(host)Distinct hosts
| stats avg(bytes) by hostAverage per host
| stats sum(bytes) AS total by hostSum renamed
| stats count by hostEvents per host
| stats count(eval(status=404)) AS not_foundCount 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

FunctionResult
countNumber of events
count(x)Events where x is non-null
dc(x)Distinct values
estdc(x)Approximate distinct count

Numeric

FunctionResult
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

FunctionResult
perc5(x)5th percentile
perc95(x)95th percentile
exactperc95(x)Exact percentile
upperperc95(x)Approximate upper bound

Values

FunctionResult
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

CommandResult
| top urlTen most common URLs
| top 20 urlTwenty most common
| top user by hostTop user per host
| top user, hostCommon pairs
| rare urlTen least common URLs
| rare 5 user by hostLeast common per host

Both add count and percent fields and return 10 results by default. Field lists are comma-separated.

See: top, rare

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

| timechart span=5m count by host
| timechart span=1h avg(cpu) by host limit=5
| chart count over status by host

timechart puts _time on the x-axis; chart uses any field. span sets the bucket width.

See: timechart, chart

Rate functions

FunctionResult
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

CommandResult
| bin _time span=1hHourly buckets
| bin bytes span=1000Fixed-width buckets
| bin latency bins=20About 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

CommandResult
| rename src AS client_ipRename a field
| rename src AS client_ip, dest AS targetRename 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

FunctionResult
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

CommandResult
| lookup dnslookup hostAdd all matching fields
| lookup dnslookup host OUTPUT ipAdd only ip
| lookup dnslookup host AS server OUTPUT ip AS server_ipRename on match
| lookup geo.csv ipUse 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

CommandResult
| inputlookup users.csvRead a lookup table
| inputlookup users.csv where active=1Filter lookup rows
| outputlookup users.csvOverwrite the table
| outputlookup users.csv append=trueAppend rows
| outputlookup users_kv key_field=usernameUpdate 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

CommandResult
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.

See: search command primer

Missing fields

CommandResult
user=*Field exists
NOT user=*Field is missing
NOT status=200Includes missing status
status!=200Requires status

field=* tests existence. != drops results where the field is missing; NOT field=value keeps them.

See: difference between != and NOT

0 Comments for this cheatsheet. Write yours!