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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...