Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 36 ยท Search Processing Language

Splunk Search Basics: Keywords, Wildcards, Booleans and Time Ranges

Write your first Splunk searches: index and sourcetype filters, keywords, quoted phrases, wildcards, AND/OR/NOT, field=value, and time ranges with earliest, latest and snap-to.

Every Splunk search begins with a search command that decides which events to retrieve. Getting this first part right makes the difference between a search that returns in a second and one that grinds through terabytes. In this lesson you learn keywords, fields, Boolean logic, wildcards and the time modifiers earliest and latest.

The examples assume web data in an index called web with sourcetype access_combined. Your names will differ.

SPL
index=web sourcetype=access_combined status=500 error

Read it left to right: events in index web, of that sourcetype, with field status equal to 500, and containing the word error anywhere in the raw text. When you separate terms with a space, Splunk assumes AND.

Good habits for the first line of any search:

  1. Name the index (and sourcetype or host) so Splunk reads only relevant buckets.
  2. Choose the narrowest time range that answers the question.
  3. Add the most selective terms next.

Keywords and phrases

  • error matches the term "error" case-insensitively. Terms are split at breakers such as spaces and punctuation.
  • "connection refused" in double quotes matches the exact phrase.
  • Field names are case-sensitive (status is not Status), but field values are case-insensitive in the search command (host=WEB01 finds web01). The where command, covered later, compares values case-sensitively.

Boolean operators

AND, OR, NOT must be uppercase. Precedence: NOT, then OR, then AND. Use parentheses to be explicit:

SPL
index=web (status=500 OR status=503) NOT host=test01

Without parentheses, status=500 OR status=503 host=web01 would be read as status=500 OR (status=503 AND host=web01), a classic mistake.

Other useful forms:

SPL
index=web status IN (500, 502, 503)
index=web status!=200
index=web NOT status=200

status!=200 also returns events that have no status field; NOT status=200 does too. To require the field to exist, add status=*.

Wildcards

* matches any characters: host=web*, uri_path=/api/*, fail*. A leading wildcard (*error) is slow because Splunk cannot use the term index efficiently; avoid it. A search of just * returns everything in the selected indexes and time range.

Python Stand-in: AND, OR, NOT and wildcards over a tiny index

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Time ranges

Splunk stores _time in every event. The time range picker sets the window, but you can also put it in the search with earliest and latest, which override the picker:

SPL
index=web earliest=-4h latest=now
index=web earliest=-7d@d latest=@d
index=web earliest="11/12/2026:00:00:00" latest="11/13/2026:00:00:00"

Relative time modifiers

A relative time is [+|-]<number><unit> plus an optional snap:

Part Meaning
-15m, -4h, -7d, -1mon, -1y Look back (units: s, m, h, d, w, mon, q, y)
now The moment the search starts
@d, @h, @w0, @mon Snap to the beginning of the day, hour, week (Sunday = w0), month
-1d@d Start of yesterday

So earliest=-1d@d latest=@d means all of yesterday: from midnight yesterday up to midnight today. Without the snap, -24h slides with the clock and gives a different window every time you run it.

Python Stand-in: relative time and snap-to-day

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

_time versus index time

_time is the event's own timestamp (taken from its text). _indextime is when Splunk indexed it. The time range filters on _time. If a forwarder was offline and sent old data late, the events still appear at their original times. Use _indextime in earliest-style filters only with where or _index_earliest/_index_latest.

Real-time searches

A real-time window (for example 5 minute window) keeps a rolling set of events and updates as data arrives. It is expensive because it holds a search open continuously; prefer a scheduled search every minute over a real-time alert.

Search modes and speed tips

  • Fast mode is quickest for exploring.
  • Specify index, sourcetype and time first; filter on indexed or literal terms before extracting fields.
  • Avoid index=* and * as the first term on busy deployments.
  • Use | head 100 while developing a search; it stops early.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which search returns events from yesterday only?

    -1d@d is midnight yesterday and @d is midnight today, so the window is exactly yesterday.
  2. 2. What does a space between two search terms mean?

    Implicit AND. Use quotes for a phrase and uppercase OR for alternatives.
  3. 3. Why is a leading wildcard such as *error slow?

    The index maps whole terms; a leading wildcard needs a scan of all terms.
  4. 4. Which timestamp does the time range filter use?

    _time is the event timestamp; _indextime is when Splunk wrote it.

Summary

  • Start every search with index, sourcetype and time; terms combine with an implicit AND.
  • OR, NOT, AND are uppercase; use parentheses and IN (...).
  • Wildcards are fine at the end of a term, bad at the start.
  • earliest and latest accept relative times and snaps such as -1d@d.

Next: The SPL pipeline: filtering, sorting and shaping results