All Apps and Add-ons

Extract user list and use in next query

MattQ
Explorer

I have a search that returns a number of UserNames. I would like to extract just the usernames [field:UserName] from the search results and then do a follow on search for all the items that have those usernames in them.

Search and return 'ListOfUsers'
Use 'ListOfUsers' to Search index=* (or separate broad search) to return ALL activity from 'ListOfUsers'

0 Karma
1 Solution

alacercogitatus
SplunkTrust
SplunkTrust

Sure.

index=* [ search your_search_for_users | table UserName ] | do_other_things

But.... subsearches are inefficient, since they consume 2 cpus per execution. A nicer way would be to keep a lookup of users, and then use the lookup in the search.

The Saved Search that runs every so often:

index=whatever find_your_users | table UserName | outputlookup interesting_users.csv

Then use it in a "sub-searchy" kind of way.

index=* other_criteria [ | inputlookup interesting_users.csv | table UserName ]

View solution in original post

alacercogitatus
SplunkTrust
SplunkTrust

Sure.

index=* [ search your_search_for_users | table UserName ] | do_other_things

But.... subsearches are inefficient, since they consume 2 cpus per execution. A nicer way would be to keep a lookup of users, and then use the lookup in the search.

The Saved Search that runs every so often:

index=whatever find_your_users | table UserName | outputlookup interesting_users.csv

Then use it in a "sub-searchy" kind of way.

index=* other_criteria [ | inputlookup interesting_users.csv | table UserName ]

David
Splunk Employee
Splunk Employee

This is a great use case for a subsearch. You would have your entire search be:

[search <search criteria for the list of users> | fields UserName] <search for activities>

The subsearch will output a series usernames that are then criteria for the broader search. Make sure you start your subsearch with "search."

0 Karma

MattQ
Explorer

That works to input a field into a more limited search. Is there a way to port those results into a wider search. Like back into index=* UserNameList

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...