Add comments to searches

You can add inline comments to the search string of a saved search by enclosing the comments in backtick characters ( ``` ).

Use inline comments to:

  • Explain each "step" of a complicated search that is shared with other users.
  • Discuss ways of improving a search with other users.
  • Leave notes for yourself in unshared searches that are works in progress.
  • Troubleshoot searches by running them with chunks of SPL "commented out".

Here is an example of a search with comments:

In the Search Bar, the comments for this search are color-coded to make the comments easier to find:

An example of a complex search formatted into separate pipe sections, with comment text added to explain each "step" of the search.

The search processor replaces comments with a space when the search is run. For example, this comment ...| stats```Let's use 'stats' to count this```count becomes ...| stats count, when run not ... | statscount.

Comments and special characters

  • SPL comments support Unicode characters.
  • Comments ignore the backslash escape character. For example: \```This is still a comment. It is not escaped.```
  • Single and double backticks within a comment are considered to be part of the comment. For example: ```This comment has an extra backtick at the end. It's a valid comment. ` ```

Comment limitations

The following table describes limitations associated with using comments:

Comment limitation Example
A comment inserted before a generating command causes the search to fail. Common generating commands are tstats, makeresults, and gentimes. ```This search returns an error``` | tstats count WHERE host=x BY source
You can't insert comments inside a quoted string. "```The search processor treats this as an SPL string, not a comment.```"

Use comments to troubleshoot a search

Keyboard shortcuts to add or remove comments

You can use the following keyboard shortcuts to add or remove comment characters in a search.

  • On Linux or Windows use Ctrl + /
  • On Mac OSX use Command + /

Add a new comment

To insert an empty set of comment characters at a specific place in your search:

  1. Position the cursor where you want the characters to appear and use the keyboard shortcut.
  2. You can then type your comment inside the comment characters.