Splunk Search

Pass a value to a map subsearch and assign it to another field

romedome
Path Finder

How can I take a value from the base search an pass it to a map search like so:

<base search> | map "search index=a | eval Oldtime=$_time$"

I can use base search values to filter and compare in the map search, but I can use them to assign values 😞 Any thoughts?

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

Try putting the values in double quotes? Also, try to rename the token to some general name and pass to subsearch (sometime that fixes the issue)

<base search> | eval Timestamp=_time| map "search index=a | eval Oldtime=\"$Timestamp$\"" 

View solution in original post

steveyz
Splunk Employee
Splunk Employee

the following worked for me:

| stats count | map search="search index=_internal | head 10 | eval x=$count$" | table x

You should see that you'll end up with 10 events all with x=0.

romedome
Path Finder

For some reason it was not working for me until I used x=\"$count$\"

0 Karma

steveyz
Splunk Employee
Splunk Employee

oh, you need to quote it for eval if it's supposed to be a string literal. Or else it will treat it as a field name or a number, which is why $count$ without the quote works if the count is just a number.

somesoni2
Revered Legend

Try putting the values in double quotes? Also, try to rename the token to some general name and pass to subsearch (sometime that fixes the issue)

<base search> | eval Timestamp=_time| map "search index=a | eval Oldtime=\"$Timestamp$\"" 

romedome
Path Finder

Wow! the quotes worked! Can you tell me why they're necessary?

I restructured the search backwards. I now have the search that generates the most information as the map search. That way I'm minimizing the amount of fields I need to pass along to the map search

Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...