Developing Dashboards, Views, and Apps for Splunk Web

 


Search language (version 2.1 and 2.2)

This documentation does not apply to the most recent version of Splunk. Click here for the latest version.

Search language (version 2.1 and 2.2)

The Splunk search API is the language that both end users and other applications use to describe their search requests to the Splunk Server. Parameters can specify what to look for, how to restrict the range of a search, how to display the results, or what special actions to perform.


Syntax

Grammar

Our nomenclature comes from Google's documentation plus the minimal augmentation necessary for Splunk's specific needs.


Splunk searches consist of one more more terms in series. In man page notation:


term [term] ...

Each term takes one of these two forms.


word

or


operator::word

This term is a single word that specifies a search for the string "apache" in each event.


apache

This term is an operator::word pair that specifies a search for events whose sourcetype metadata has the value "apache."


sourcetype::apache

There are four basic types of terms.


Boolean operators

AND, OR and NOT, in uppercase only, are treated as Boolean logic operators that specify a logical inclusive or exclusive relationship between the terms on either side of them.


error OR (success NOT login)

Punctuation

Terms are separated by one or more space characters.


Two colons --:: -- separate the components of operator::word terms.


host::web01

A few special characters -- :: * + ++ () [] "" -- change the way terms are evaluated. Some of these are used alone, some in pairs.


host::web0*

+*error*

report::[select _user from resultstable]

These special punctuators are listed in detail below.


Precedence

Left to Right

In the case of conflicting search parameters, the rightmost term takes precedence. For example, the search below will return 10 results, not 5.


foo maxresults::5 maxresults::10

Boolean operators

The exception to left-to-right precedence are Boolean operators. They are evaluated in this order, from highest to lowest precedence:



Special characters

 :: two colons

Two colons in a row, if preceded by a modifier, separate the modifier from its value.


maxresults::10

host::jupiter

If not preceded by a recognized modifier, colons are treated as literal search terms. The example below searches for the literal string "fe80::1," which is part of a network configuration event.


fe80::1

* asterisk

An asterisk at the start of a word matches all words that end with the rest of the term.


*log

An asterisk at the end of a word, or at the end of an operator::word pair, matches all terms that start with the preceding part of the term.


/var/log/*

host::*

The asterisk cannot be used to wildcard operators, only words. For example =source*::foo= is not supported.


+ plus sign

A plus sign at the start of a term designates the term as a literal string to be matched, free of operators or special punctuation. For example, the search below find the literal string "foo::bar*" in events.


+foo::bar*

To search for a single "+" ...


++

To search for a term that starts with a + ...


++foobar

( ) parentheses

Parentheses around a Boolean grouping enforce the precedence of that grouping over the normal Boolean precedence order.


term1 OR (term2 AND term3)

[ ] square brackets

Brackets after a report:: modifier constrain the SQL command for the report.


report::[select * from resultstable]

To search for a term that contains a [ square bracket, escape it by wrapping it in quotes


"[bar]"

" " quote marks

Quote marks around a single term without whitespace are ignored. The term within is evaluated normally.


"whatever"

Quote marks around a term that includes an operator can match whitespace in the word, if it was indexed as metadata with the space.


"username::Joe Smith"

Quote marks around multiple terms separated by whitespace are currently not supported. The search will return no results. This will change in the next major release.


"this will not work yet"

Quote marks around a left bracket "[" escape the bracket to allow searching for events that contain left brackets.


"[bar"

 !++cmd++ !++param1++ !++param2++

These idiomatic command and parameter names execute a few deliberately obscure, undocumented commands.


!++cmd++::roll

This example would change the root logging level within the Splunk Server to "debug"


!++cmd++::logchange !++param1++::root !++param2++::DEBUG

Operators

Boolean Operators

These operators are used to specify the relationships between other terms.


AND

Search strings have an implied AND between each term.


OR

NOT

( )

Search Operators

sourcetype::

source::

host::

savedsplunk::

eventtype::

tag::

typetag::

Synonym for tag::


eventtypetag::

Synonym for tag::


maxresults::

All searches have a default of maxresults::10000


hosttag::

index::

All searches have a default of index::default


related::

relatedmaxwords::

All searches have a default of relatedmaxwords::5


relatedweight::

All searches have a default of relatedweight::1.0


delete::source::

delete::host::

deleterestrict::host::bar

linecount::

report::

server::

similar

There is no similar modifier; it's a special syntax version of eventtype.


eventtype::?91-3

Time Operators

Time operators apply to the whole query. These two queries are equivalent.


( foo NOT bar daysago::1 ) OR ( baz NOT bat hoursago::1 )

( foo NOT bar ) ( baz NOT bat ) hoursago::1

Start time operators

starttime::

startdaysago::

startminutesago::

starthoursago::

startmonthsago::

starttimeu::

End time operators

endtime::

enddaysago::

endminutesago::

endhoursago::

endmonthsago::

endtimeu::

timeformat::

All searches have a default of timeformat::%m/%d/%Y:%H:%M:%S


Time span operators

Time span operators are always applied from the last time boundry set. If an endtime operator is closest to the left of a timespan operator, it will be applied to the starttime.


These two queries are equivalent.


enddaysago::1 searchtimespanhours::5

starthoursago::29 enddaysago::1

If no start time or end time operator is supplied before setting the time span an error is returned.


searchtimespanhours:

searchtimespanminutes:

searchtimespandays::

searchtimespanmonths::

Ago operators

daysago::

minutesago::

hoursago::

monthsago::

Date & time operators

Note that these operators operate on the exact text that was in the file so an event file from a different timezone that was timestamped as happening at 8am will not match hour::8


year::

month::

mday::

wday::

hour::

minute::

second::

zone::

This documentation applies to the following versions of Splunk: 2.1 , 2.2 , 2.2.1 , 2.2.3 , 2.2.6 View the Article History for its revisions.


You must be logged into splunk.com in order to post comments. Log in now.

Was this documentation topic helpful?

If you'd like to hear back from us, please provide your email address:

We'd love to hear what you think about this topic or the documentation as a whole. Feedback you enter here will be delivered to the documentation team.

Feedback submitted, thanks!