Splunk Search

Lookup against Splunk Search

rizzo75
Path Finder

I need to run a search, then run another search to calculate a specific value. Almost like a lookup with splunk commands.

search ... | fields id count

for each event run: search ... id=$id$ | eval count=$count$ | ... calculations ... | stats sum(n) as N

The output would have all values:

id    | count | N
------------------------
111 | 222     | 333

What is the best way to achieve this?

Thanks,

Joe

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Using your example, you could do this:

... | map maxsearches=42 [search ... id=$id$ | eval count = $count$ | ... calculations ... | stats sum(n) as N]

That'll give you up to 42 rows with a column N containing the sum. Depending on your calculations, it might be a lot faster to do something like this:

... | ... calculations, possibly involving some "by id" ... | stats sum(n) as N by id

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Using your example, you could do this:

... | map maxsearches=42 [search ... id=$id$ | eval count = $count$ | ... calculations ... | stats sum(n) as N]

That'll give you up to 42 rows with a column N containing the sum. Depending on your calculations, it might be a lot faster to do something like this:

... | ... calculations, possibly involving some "by id" ... | stats sum(n) as N by id
0 Karma

rizzo75
Path Finder

I was able to achieve the necessary results using the map command, then joining back on the initial search.

earliest="-24h@h" latest="now" index=foo sourcetype=mysrc state=7 type!=9
| join type=outer usetime=True id [ search 
  index=foo sourcetype=mysrc state=7 type!=9
  | map maxsearches=500 search=" search
    index=bar sourcetype=othersrc … id = $id$
    | eval count=$count$
    | evals and such …
    | eval number=somenumber*othernumber
    | stats sum(number) as sum_number values(id) as id" ]
0 Karma

musskopf
Builder

Have a look on the map command... Provide some additional event data and expected results as vasanthmss mentioned to help writing the search.

0 Karma

vasanthmss
Motivator

provide some sample events and expected result
If possible provide the search query you are running.

V
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!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...