Splunk Search

Splunk Dynamic search using lookup

rishiaggarwal
Explorer

I wish to populate a list of index names ( > 1) from a lookup table to a search query.

Indexlookup.csv -->

COL1


index1
index2
index5
index9

search -->

query | search index="index1" OR index="index2" OR index="index5" OR index="index1" | .........................

0 Karma
1 Solution

Eshaac
Engager

To do this you should create a csv file which contains the header index
e.g. index
xyz
xyz
xzy

exclude adding "index=" to the index value on the lookup.
once this lookup is created use this search string

[|inputlookup "your_lookup_name"
| search index=*
| eval search="(index=".index.") OR"
| stats values(search) as search
| eval search=tostring(search)
| eval search=substr(search,0,len(search)-3)]

this will then amalgamate the different indexes and run it!

View solution in original post

0 Karma

Eshaac
Engager

To do this you should create a csv file which contains the header index
e.g. index
xyz
xyz
xzy

exclude adding "index=" to the index value on the lookup.
once this lookup is created use this search string

[|inputlookup "your_lookup_name"
| search index=*
| eval search="(index=".index.") OR"
| stats values(search) as search
| eval search=tostring(search)
| eval search=substr(search,0,len(search)-3)]

this will then amalgamate the different indexes and run it!

0 Karma

niketn
Legend

I am not sure what you imply by " index names ( > 1) ", however, instead of using the search you have mentioned you can try the following:

<YourBaseSearch> [|inputlookup Indexlookup.csv | rename COL1 as index| table index]
| <Your Remaining Search>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

dineshraj9
Builder

Try this way -

query | search [ | inputlookup Indexlookup.csv | rename COL1 as index | table index ] | ...

OR

query | search [ | inputlookup Indexlookup.csv | rename COL1 as index | table index | format ] | ...
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi rishiaggarwal,
to do this, you have to put your indexes in a lookup with column name called index and use it in a subsearch

your_search [ | inputlookup your_indexes.csv | fields index ] | ...

I don't like this solution, I prefer to put indexes in an eventtype and use it in my searches.

Bye.
Giuseppe

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...