Splunk Search

Having a problem substituting value for earliest in a map command

timpgray
Path Finder

I am attempting to use the ‘map’ command with a sub search. In the subsearch I am using I wish to use the value of _time for the value of ‘earliest’ in the subsearch. Here is a simplified representation of the query I am attempting to perform:

index = "yyyy" | convert timeformat="%m/%d/%Y:%H:%M:%S" ctime(_time) as RequestRecvd_earliest | map [search index = "zzzz" earliest=$RequestRecvd_earliest$]

When I run this query, I get the following error:

Invalid value "$RequestRecvd_earliest$" for time term 'earliest’

This happens if I use the values ‘earliest’ or ‘latest’. If I use some other field name such as ‘bob’, I do not get this error.

Does anyone have any idea about what is going on here?

1 Solution

jonuwz
Influencer

Pretty sure earliest accepts an epoch value, so all the conversion is not needed.

This returns 10 events which is correct :

* | head 10 | tail 1 | rename _time as time | map search="search * earliest=$time$"

It doesnt like $_time$ for some reason, so you have to rename it.

The above search doesn't seem to work with the [ ] notation, I always have problems with it.

View solution in original post

jonuwz
Influencer

Pretty sure earliest accepts an epoch value, so all the conversion is not needed.

This returns 10 events which is correct :

* | head 10 | tail 1 | rename _time as time | map search="search * earliest=$time$"

It doesnt like $_time$ for some reason, so you have to rename it.

The above search doesn't seem to work with the [ ] notation, I always have problems with it.

timpgray
Path Finder

OK thanks for the info. I think you may have indirectly answered my question. Your observation that the subsearch notation does not work seems to be the key. If I instead use your suggested notation, it works as expected. I also noticed that the parser is very particular about the exact format – ‘search=”…”’ works while ‘search = “…”’ (notice the spaces around ‘=’) does not work. This is probably what steered me towards the subsearch notation earlier. I wonder if subsearches make sense here since technically they are run first, which would not useful in this scenario

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...