Splunk Search

Splunk Search For Exact Word

sajbutler
Path Finder

Hi

When I execute a search for "foo", I only want events that have the word foo and not events that have words like foo.bar or bar.foo.

Any suggestions?

SAJB

Tags (2)

Meharkant123
New Member

not workind both the command 😞
"\sfoo\s"
".\sfoo\s."

still getting foobar

0 Karma

richgalloway
SplunkTrust
SplunkTrust

@Meharkant123 This thread is almost 6 years old. For better chances at a helpful response, please post a new question.

---
If this reply helps you, Karma would be appreciated.
0 Karma

lguinn2
Legend

First, Splunk normally searches by words, not by characters. So "foosball" will always be eliminated, because there is no "word" foo.

"foo.bar" and "bar.foo" are trickier because you have to understand what defines a "word" in Splunk. Whitespace always delimits words, but internal punctuation may/may not. It depends on the segmentation. Inner segmentation says that punctuation delimits words, just like whitespace. Outer segmentation says that only whitespace delimits words. By default, Splunk indexes both ways, and calls it full segmentation.

So normally, when you search for "foo", you will get "foo.bar" and "bar.foo".

To take more control of how Splunk searches, use the regex command. It allows you to keep or eliminate events that match a regular expression. This will let you search with case sensitivity or by characters.

For example:

sourcetype=yoursourcetype foo
| regex _raw=".*\sfoo\s.*"

will match any event that has "foo" in it, where foo is not capitalized and is surrounded by white space.

Note that I also included foo in the initial search. Why? Well, it is more efficient to eliminate all the events that don't have foo anywhere in the event before you apply the regex. For other kinds of searches, that might not be helpful, though.

Ayn
Legend

Excellent answer. I'll just add that you could also omit the leading and trailing .* because Splunk will match on that implicitly anyway.

regex _raw="\sfoo\s"
0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...