
Help reading searches in Splunk Light
The Search bar contains features to help you read, parse, or interpret the Splunk Search Processing Language (SPL) syntax. The syntax highlighting feature displays parts of SPL in different colors. There are also keyboard shortcuts to help you find information in your searches.
Syntax highlighting
With syntax highlighting, the SPL commands, arguments, functions, and keywords are color-coded to make it easier to read a search.
Consider the following search.
sourcetype=access_* | timechart count(eval(action=purchase)) BY productName usenull=false useother=false
With syntax highlighting turned on, the search is easier to read. The following image shows the syntax highlighting Light theme.
By default, syntax highlighting is turned on.
Color codes
The color coding that is used for the search syntax depends on the color theme that is implemented. The Light theme is the default theme. The color codes for the Light theme are described in the following table.
Syntax component | Color | Example |
---|---|---|
Commands | Blue | ...timechart |
Command arguments | Green | ...timechart usenull=false |
Functions | Pink | ...timechart count |
Keyword modifiers and Boolean operators | Orange | ...timechart count BY productName |
Syntax validation
If command, argument, function, or boolean operator is not spelled or capitalized correctly the term is not highlighted in color. The lack of color helps you ensure that the search is using the correct syntax.
If you specify incorrect data type for an argument, the value turns red. For example, the limit
argument for the top
command expects an integer. If you type ...|top limit=false
the term false
is highlighted in red because it is not a integer.
Turn off syntax highlighting
You can turn syntax highlighting off.
- On the Splunk bar, select [User icon] > Account Settings.
- In the Search Preferences section under Syntax highlighting, select Black on white.
- Click Save.
Color themes
You can change the appearance of the criteria in the Search bar by specifying a color theme. There are several themes to choose from.
Theme name | Theme colors | Notes |
---|---|---|
Light theme | White background. Black text. Colors for commands, arguments, clauses, functions, keys (in a key-value pair), values, and comments. | Default theme |
Dark theme | Black background. Light grey text. Colors for commands, arguments, clauses, functions, keys (in a key-value pair), values, and comments. | |
Black on white | White background. Black text. No other colors. |
Change your theme
- On the Splunk bar, select [User icon] > Account Settings.
- In the Search Preferences section under Syntax highlighting, select the color theme that you want to use.
- Click Save.
Auto-format search syntax
As you build a search, you can set up the Splunk software to format the search syntax as you type.
Auto-format works on searches that you type
The auto-format feature works on searches that you type into the Search bar. If you paste a search into the Search bar or select a search from Search History, the search is not automatically formatted even when the auto-format feature is turned on.
To apply auto-formatting to a search that you paste into the Search bar or select from Search History, use the keyboard shortcut to apply auto-formatting to that specific search.
- On Linux or Windows use Ctrl + \ . On many non-English keyboards you can use Ctrl + Shift + F .
- On Mac OSX use Command + \ . On many non-English keyboards you can use Command + Shift + F .
Characters that trigger auto-format
Character | Automatic formatting |
---|---|
Pipe ( | ) | The pipe is placed on a new line to separate each new piped section of your search criteria. |
Left square bracket ( [ ) | The left square bracket, which signifies the start of a subsearch, is placed on a new line and indented several spaces. |
If the pipe or left bracket is inside a quoted string, the auto-format is not triggered.
Turn on Search auto-format
By default, automatic formatting of search syntax is turned off. You can turn on the automatic formatting of the search syntax in Search Preferences.
- On the Splunk bar, select [User icon] > Account Settings.
- In the Search Preferences section under Search auto-format, select On.
- Click Save.
Changing the options in Search Preferences, changes the setting only for you. It does not impact the setting for other users.
Number search lines
To make reading your searches easier, you can display line numbers in the Search bar.
A row in the Search bar is not a line
The line numbering feature applies numbers only to lines. A row in the Search bar is not necessarily a line. You might have a long line that spans multiple rows in the Search bar, but is still only one line.
For example, if you paste a long search into the Search bar that has not already been formatted with multiple lines, the search has one line number and spans multiple rows.
You can create lines in the Search bar by using the following methods. You can create lines in the Search bar by using the following methods.
- The Search auto-formatting feature is turned on and you type a pipe character or left square bracket.
- You use the Search bar shortcuts to auto-format the current search.
- You press Shift + Enter to split the active row at the cursor. Pressing Enter does not create a new line in the Search bar.
Turn on line numbering
By default, line numbering is turned off. You turn on line numbering in Search Preferences.
- On the Splunk bar, select [User icon] > Account Settings.
- In the Search Preferences section under Show line numbers, select On.
- Click Save.
Changing the options in Search Preferences changes the setting only for you. It does not impact the setting for other users.
Search bar shortcuts
In the Search bar, you can use keyboard shortcuts to help you develop, read, and parse your search criteria.
Make searches easier to read
Long searches can be difficult to read. For example, the following search uses multiple commands and includes many occurrences of renaming columns in the search results.
sourcetype=access_* status=200 | stats count AS views count(eval(action="addtocart")) AS addtocart count(eval(action="purchase")) AS purchases by productName | eval viewsToPurchases=(purchases/views)*100 | eval cartToPurchases=(purchases/addtocart)*100 | table productName views addtocart purchases viewsToPurchases cartToPurchases | rename productName AS "Product Name", views AS "Views", addtocart as "Adds To Cart", purchases AS "Purchases"
The following image shows how this search appears in the Search bar.
You can use a keyboard shortcut to parse each pipe section on a separate line. Any subsearches are indented.
- On Linux or Windows use Ctrl + \ . You can also use Ctrl + Shift + F, which works well with many non-English keyboards.
- On Mac OSX use Command + \. You can also use Command + Shift + F, which works well with many non-English keyboards.
The results of the shortcut are shown in the following image.
You can also use Shift + Enter to force a new line. See Line and word shortcuts in the Splunk Enterprise Search Manual.
Expand your search
You can see the contents of your search with a keyboard shortcut, Command-Shift-E (Mac OSX) or Control-Shift-E (Linux or Windows) from the Search bar in the Search page. This opens a preview that displays the expanded search string, including all search macros and saved searches. If syntax highlighting or line numbering are turned on, those features also appear in the preview.
You can copy parts of the search in the preview. You can also click Open in Search to run your search in a new window from the preview.
Highlight search terms
- To highlight all of the occurrences of a word in the search, double-click on that word.
Locate matching parenthesis
- Position your cursor immediately after an open or close parenthesis. The matching parenthesis is highlighted.
Undo and Redo shortcuts
Use these keyboard shortcuts to undo and redo actions in the Search bar.
Action | Linux or Windows | Mac OSX |
---|---|---|
Undo the previous action. | Ctrl + Z | Command + Z |
Redo the previous action. | Ctrl + Y or Ctrl + Shift + Z |
Command + Y or Command + Shift + Z |
Search assistant window shortcuts
With the Compact mode of the search assistant, you can use keyboard shortcuts to select items in the list, and close and reopen the search assistant window.
Action | Linux or Windows | Mac OSX |
---|---|---|
Move your cursor into the search assistant window. | Down arrow key | Down arrow key |
Close the search assistant window. | ESC | ESC |
Reopen the search assistant window. | Ctrl + Space | Control + Space |
Select an item in the search assistant window and insert it into the Search bar. | Use the Up arrow and Down arrow keys to highlight the item and press Enter. | Use the Up arrow and Down arrow keys to highlight the item and press Enter. |
Toggle between the list and the Learn More link in the search assistant window. | Tab | Tab |
Find and replace shortcuts
Use the following keyboard shortcuts to find and replace terms in the Search bar.
Action | Linux or Windows | Mac OSX |
---|---|---|
Find a term. | Ctrl + F | Command + F |
Find and replace a term. | Ctrl + H | Command + Option + F |
Line and word shortcuts
The distinction between rows and lines is important to understand when you use keyboard shortcuts to manipulate rows or lines in your search criteria in the Search bar.
- Long searches appear on multiple rows in the Search bar.
- If the search is not parsed, the search is one line.
- If the search is parsed, separating each piped section and subsearch into its own line, a row is the same as a line.
Action | Linux or Windows | Mac OSX |
---|---|---|
Split the active row at the cursor. | Shift + Enter | Shift + Enter |
Remove the active line. If the search is one line with multiple rows and not parsed into separate lines, the entire search is removed. | Ctrl + D | Command + D |
Copy the active row and place the copy below the active row. | Alt + Shift + Down arrow | Command + Option + Down arrow |
Copy the active row and place the copy above the active row. | Alt + Shift + Up arrow | Command + Option + Up arrow |
Move the active row down one row. | Alt + Down arrow | Option + Down arrow |
Move the active row up one row. | Alt + Up arrow | Option + Up arrow |
Remove the search criteria from the cursor to the end of the row. | Alt + Delete | Control + K |
Remove the search criteria from the cursor to the start of the row. | Alt + Backspace | Command + Delete |
Remove the word or space to the right of the cursor. | Ctrl + Delete | Alt + Delete |
Remove the word or space to the left of the cursor. | Ctrl + Backspace | Option + Delete |
PREVIOUS Help building searches in Splunk Light |
NEXT View search results in Splunk Light |
This documentation applies to the following versions of Splunk® Light (Legacy): 6.6.0, 6.6.1, 6.6.2, 6.6.3, 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6
Feedback submitted, thanks!