Splunk Search

Using eval from outer search to inner

dhruv101
Path Finder

Hi,

I am aware that an eval in the parent search cannot be used in a subsearch like this -

| eval foo = .....  | eval bar = [search index='event' | eval alice = foo/10]

if subsearch is out of the question, then are joins the only way we can achieve this? Also, is it possible to return a multivalued field(list) in the above query and store it in bar, instead of returning a single number(like count using return $count). If so, how is it done?

Basically if I have an eval in one search and I want to extract a list of data from another search index where that eval needs to be used, how is it achieved?

Thanks.

0 Karma

MuS
Legend

Hi dhruv101,

simply switch the searches, so that your sub search returns the eval result to the base search.
Try this run everywhere example, which will not any result:

index=_* 
    [ search index=_audit 
    | stats count by sourcetype 
    | sort - count 
    | head 5 
    | eval foo=case(count > 1000, "lots", count < 1000, "less", 1=1, "unknown") 
    | table foo 
    | format ]

But looking at the litsearch in job inspector you can see that foo was used in the base search 😉

litsearch (index=_* foo="lots") | fields keepcolorder=t "_bkt" "_cd" "_si" "host" "index" "linecount" "source" "sourcetype" "splunk_server"

Hope this helps ...

cheers, MuS

0 Karma
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...