Splunk® Enterprise

Search Reference

Download manual as PDF

Splunk Enterprise version 5.0 reached its End of Life on December 1, 2017. Please see the migration information.
This documentation does not apply to the most recent version of Splunk. Click here for the latest version.
Download topic as PDF


Use the search command to retrieve events from your indexes, using keywords, quoted phrases, wildcards, and key/value expressions. The command is implicit when it's the first search command (used at the beginning of a pipeline). When it's not the first command in the pipeline, it's used to filter the results of the previous command.

After you retrieve events, you can apply commands to them to transform, filter, and report on them. Use the vertical bar "|" , or pipe character, to apply a command to the retrieved events.


Retrieve events from indexes or filter the results of a previous search command in the pipeline.


search <logical-expression>


Syntax: <time-opts> | <search-modifier> | [NOT] <logical-expression> | <index-expression> | <comparison-expression> | <logical-expression> [OR] <logical-expression>
Description: Includes all keywords or key/value pairs used to describe the events to retrieve from the index. These filters can be defined using Boolean expressions, comparison operators, time modifiers, search modifiers, or combinations of expressions.

Logical expression

Syntax: <field><cmp><value>
Description: Compare a field to a literal value or values of another field.
Syntax: "<string>" | <term> | <search-modifier>
Description: Describe the events you want to retrieve from the index using literal strings and search modifiers.
Syntax: [<timeformat>] (<time-modifier>)*
Description: Describe the format of the starttime and endtime terms of the search

Comparison expression

Syntax: = | != | < | <= | > | >=
Description: Comparison operators. You can use comparison expressions when searching field/value pairs. Comparison expressions with "=" and "!=" work with all field/value pairs. Comparison expressions with < > <= >= work only with fields that have numeric values.
Syntax: <string>
Description: The name of a field.
Syntax: <string> | <num>
Description: An exact or literal value of a field. Used in a comparison expression.
Syntax: <lit-value> | <field>
Description: In comparison-expressions, the literal (number or string) value of a field or another field name.

Index expression

Syntax: "<string>"
Description: Specify keywords or quoted phrases to match. When searching for strings and quoted strings (anything that's not a search modifier), Splunk searches the _raw field for the matching events or results.
Syntax: <sourcetype-specifier>|<host-specifier>|<source-specifier>|<savedsplunk-specifier>|<eventtype-specifier>|<tag-specifier>
Description: Search for events from specified fields or field tags. For example, search for one or a combination of hosts, sources, source types, saved searches, and event types. Also, search for the field tag, with the format: </code>tag=<field>::<string></code>.

Time options

Splunk allows many flexible options for searching based on time. For a list of time modifiers, see the topic "Time modifiers for search"

Syntax: timeformat=<string>
Description: Set the time format for starttime and endtime terms. By default, the timestamp is formatted: timeformat=%m/%d/%Y:%H:%M:%S .
Syntax: starttime=<string> | endtime=<string> | earliest=<time_modifier> | latest=<time_modifier>
Description: Specify start and end times using relative or absolute time.
  • You can also use the earliest and latest attributes to specify absolute and relative time ranges for your search. Read more about this time modifier syntax in "About search time ranges" in the Search manual.
Syntax: starttime=<string>
Description: Events must be later or equal to this time. Must match timeformat.
Syntax: endtime=<string>
Description: All events must be earlier or equal to this time.


The search command enables you to use keywords, phrases, fields, boolean expressions, and comparison expressions to specify exactly which events you want to retrieve from a Splunk index(es).

Some examples of search terms are:

  • keywords: error login
  • quoted phrases: "database error"
  • boolean operators: login NOT (error OR fail)
  • wildcards: fail*
  • field values: status=404, status!=404, or status>200

Read more about how to "Use the search command to retrieve events" in the Search Manual.

Quotes and escaping characters

Generally, you need quotes around phrases and field values that include white spaces, commas, pipes, quotes, and/or brackets. Quotes must be balanced, an opening quote must be followed by an unescaped closing quote. For example:

  • A search such as error | stats count will find the number of events containing the string error.
  • A search such as ... | search "error | stats count" would return the raw events containing error, a pipe, stats, and count, in that order.

Additionally, you want to use quotes around keywords and phrases if you don't want to search for their default meaning, such as Boolean operators and field/value pairs. For example:

  • A search for the keyword AND without meaning the Boolean operator: error "AND"
  • A search for this field/value phrase: error "startswith=foo"

The backslash character (\) is used to escape quotes, pipes, and itself. Backslash escape sequences are still expanded inside quotes. For example:

  • The sequence \| as part of a search will send a pipe character to the command, instead of having the pipe split between commands.
  • The sequence \" will send a literal quote to the command, for example for searching for a literal quotation mark or inserting a literal quotation mark into a field using rex.
  • The \\ sequence will be available as a literal backslash in the command.

Unrecognized backslash sequences are not altered:

  • For example \s in a search string will be available as \s to the command, because \s is not a known escape sequence.
  • However, in the search string \\s will be available as \s to the command, because \\ is a known escape sequence that is converted to \.

Search with TERM()

You can use the TERM() directive to force Splunk to match whatever is inside the parentheses as a single term in the index. TERM is more useful for cases where the term contains minor segmenters, such as periods and commas, and is bounded by major segmenters, such as spaces or commas. In fact, TERM does not work for terms that are not bounded by major breakers.

Search with CASE()

You can use the CASE() directive to search for terms and field values that are case-sensitive.


The following are just a few examples of how to use the search command. You can find more examples in the Start Searching topic of the Splunk Tutorial.

Example 1: This example demonstrates key/value pair matching for specific values of source IP (src) and destination IP (dst).

src="10.9.165.*" OR dst=""

Example 2: This example demonstrates key/value pair matching with boolean and comparison operators. Search for events with code values of either 10 or 29, any host that isn't "localhost", and an xqp value that is greater than 5.

(code=10 OR code=29) host!="localhost" xqp>5

Example 3: This example demonstrates key/value pair matching with wildcards. Search for events from all the webservers that have an HTTP client or server error status.

host=webserver* (status=4* OR status=5*)

Example 4: This example demonstrates how to use search later in the pipeline to filter out search results. This search defines a web session using the transaction command and searches for the user sessions that contain more than three events.

eventtype=web-traffic | transactions clientip startswith="login" endswith="logout" | search eventcount>3


Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has using the search command.


This documentation applies to the following versions of Splunk® Enterprise: 5.0, 5.0.1, 5.0.2, 5.0.3, 5.0.4, 5.0.5, 5.0.6, 5.0.7, 5.0.8, 5.0.9, 5.0.10, 5.0.11, 5.0.12, 5.0.13, 5.0.14, 5.0.15, 5.0.16, 5.0.17, 5.0.18

Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

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

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters