Dashboards & Visualizations

Search a field for each word in a token separately

landen99
Motivator

Is there a way to search a field for each word in a token?
Let's say that a user enters:

$mytoken$ = "value1 value2"

into a dashboard form and you want a panel to:

index=myindex $mytoken$ | search field1=value1 OR field1=value2

How do I search for either value in that field? The user may enter more than 2 words in the input field and any word entered should be added to the "OR" list.

Maybe a subsearch like:

| search [| stats count | eval field1=$mytoken$ | table field1 | makemv field1 delim=" " allowempty=t| mvexpand field1 ]

Is the subsearch approach a good idea or is there a better way?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Subsearch is indeed the way to go.

index=myindex [ |gentimes start=-1 | eval field="\"".$mytoken$."\"" | table field | makemv field | mvexpand field] | rest of the search

View solution in original post

0 Karma

jeffland
SplunkTrust
SplunkTrust

You should make your input do the work for you. Select your input to be a multiselect and set the following: Token Prefix="(", Token Suffix=")", Token Value Prefix="field 1=", Delimiter=" OR " (that's space, OR, and space!).
This will make your input format your results the way you need them, there is a nice little line that will give you a preview of what it looks like in this window.

Now to populate your input with options to select, you could either enter them statically, but you can also do that dynamically if there are more than a few options and/or they can change. To populate it dynamically, use the search box at the bottom of the window and enter a search such as

index=myindex | top field1

Don't forget to enter field1 in Field For Label and Field For Value.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Subsearch is indeed the way to go.

index=myindex [ |gentimes start=-1 | eval field="\"".$mytoken$."\"" | table field | makemv field | mvexpand field] | rest of the search
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...