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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...