Splunk Search

Why am I unable to search in field?

karina25
Engager

Hello All,

I have a problem with my search.

The following search works:

 

index=test_index sourcetype=test_sourcetype 
| search Modulename IN ("Test_One","Test_Two")

 

 However, this search does not work:

 

index=test_index sourcetype=test_sourcetype 
| eval helper_modulename = replace("Test_One&form.Modulename=Test_Two", "&form.Modulename=", "\",\"")
| eval helper_modulename = "\"" . helper_modulename . "\""
| search Modulename IN (helper_modulename)

 

The result of helper_modulename is the same string I use in the search that works:

karina25_0-1655971882417.png

Can anyone tell me what I am doing wrong and what needs to be adapted to make it work? 🙂

Thank you all in advance!

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The IN operator expects a list of one or more literals.  It can't handle a field containing a list of literals.  Try using a subsearch to specify the IN values.

index=test_index sourcetype=test_sourcetype
| search Modulename IN ( 
    [| makeresults 
    | eval helper_modulename = replace("Test_One&form.Modulename=Test_Two", "&form.Modulename=", "\",\"") 
    | eval helper_modulename = "\"" . helper_modulename . "\"" 
    | return $helper_modulename]) 

 

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

View solution in original post

karina25
Engager

Thank you so much! This works 🙂

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The IN operator expects a list of one or more literals.  It can't handle a field containing a list of literals.  Try using a subsearch to specify the IN values.

index=test_index sourcetype=test_sourcetype
| search Modulename IN ( 
    [| makeresults 
    | eval helper_modulename = replace("Test_One&form.Modulename=Test_Two", "&form.Modulename=", "\",\"") 
    | eval helper_modulename = "\"" . helper_modulename . "\"" 
    | return $helper_modulename]) 

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...