Splunk Search

Set "latest" search time to 7 days after "earliest"

wu_weidong
Path Finder

Hi all,

I'm trying to set the search period such that "earliest" is a specific day, and "latest" is 7 days after that. For this example, I chose "earliest" to be 159595200, which is Jul 29, and I would like the search period to be 7/29/20 12AM to 8/5/20 12AM.

My query is

 

 

index=test earliest="1595952000" 
| eval latest=relative_time(earliest,"+7d")
| ...
| bin _time span=7d
| dedup _time fieldA
| stats count by _time fieldB

 

 

Splunk searches from 7/29/20 to 8/11/20 (i.e. now). It seems to ignore "latest".

I've also tried 

 

 

index=test
| eval earliest="159595200"
| eval latest=relative_time(earliest, "+7d")
|...

 

 

In this case, Splunk searches from 7/29/20 to 7/30/20, i.e. only for 1 day.

What is wrong with my query, and why is my "latest" ignored?

Thank you.

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

earliest and latest are keywords only within the search command (which is implied before the first |).  In other contexts, it's just an ordinary field.  That's why they have no effect on the time being searched.

Here is a workaround that may work for you.

| makeresults | eval earliest=1595952000 | eval latest=relative_time(earliest,"+7d") 
| map search="search index=test earliest=$earliest$ latest=$latest$ | 
| ...
| bin _time span=7d
| dedup _time fieldA
| stats count by _time fieldB"
---
If this reply helps you, Karma would be appreciated.
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...