Search performance is key to an efficient Splunk environment – no one wants to be waiting around forever waiting for search results to load. If your Splunk searches are taking a long time to run, here are simple things you can do to improve them.

1. Be specfic

The most important thing to be specific about is the index and time-range of your search – avoid searching index=* or doing all-time searches.

Splunk will return any event that includes any of the terms that appear before the first pipeline in your search. This is a time-consuming part of the process, and you should aim to return only the events you need. More search terms before the first pipe means that Splunk needs to return fewer events to you, speeding the process up. If you know that the keyword you are searching for appears in a certain field, search for field=keyword in order to make the search more efficient.

2. Wildcard with care

You can use wildcards (*) in your searches, but make sure that they only replace the end of a string. A wildcard in the middle of a string will return inconsistent and inaccurate results, especially if it contains punctuation. If you start a search term with *, it will search for everything, which is obviously going to be time-consuming.

3. Use TERM()s

This is one of the most powerful ways you can improve search times in Splunk, but not many people know about it. Understanding why TERM() is so important requires a bit of an explanation of how Splunk works, so bear with me for a few minutes.

Splunk stores your data in buckets based on their index and timestamp and keeps track of the contents using a tsidx file, a time-series index that lists each unique term in your data and tells Splunk where to find it amongst the raw data.

When you search, Splunk takes everything in your search up to the first pipe and splits it into unique terms using major and minor breakers. For example:

  • “ERROR HttpListener – Exception while processing request” becomes ERROR Exception HttpListener processing request while
  • becomes 1 168 192 and
  • becomes com idelta name and

Major and Minor breakers

Major breakers in Splunk include:
a space, a new line, a carriage return, a tab, and the following symbols: [ ] < > ( ) { } | ! ; , ‘ ” *

Minor breakers include:
/ : = @ . – $ # % \\ _

Splunk will then look at the specific buckets indicated by the time range and index you specify, and then scan the tsidx for the terms in your search, returning any event that matches any of those terms.

By using the TERM command, you can tell Splunk to find a string that includes minor breakers, provided it is surrounded by major breakers. For example, if you search for an IP address like without the TERM command, Splunk will split that into several terms at the period (a minor breaker) and look for each of those. If your data contains several IP addresses that include one of those terms, Splunk will return all of them. By searching for TERM(, Splunk will only return the events with that exact IP address in them. However, you should be careful, as this would not return an event where the IP address was preceded by a minor breaker, such as “ip=” – you’d need to add TERM(ip= to your search.

To get an idea of the terms present in a specific index, you can use the walklex command. This is a generating command that should be the first thing in your search, preceded by a pipe:

| walklex index=_internal

You can specify whether to list unique field names (type=field), indexed field terms (type=fieldvalue) or terms that aren’t associated with a field name (type=term).

It’s a complex tool to understand, but when used properly, TERM() can majorly improve your Splunk search.

For 2021 we’ve committed to posting a new Splunk tip every week!

If you want to keep up to date on tips like the one above then sign up below:

Subscribe to our newsletter to receive regular updates from iDelta, including news and updates, information on upcoming events, and Splunk tips and tricks from our team of experts. You can also find us on Twitter and LinkedIn.


* indicates required
Posted by:Becky Nielsen

Becky is a certified Splunk Admin, who has been working for iDelta since graduating from CodeClan's Professional Software Development course in 2019. Previously an archivist at several institutions around the UK, she holds an MSc in Information Management and Preservation from the University of Glasgow.