Splunk Search

How to filter a result with two timestamp ?

mah
Builder

Hi,

I have a search which I want to optimise by replace the join command : 

index="AAA" sourcetype=BBB
| stats count(OK) as OK as TOTAL by Date ID
| bin Date span=1d
| stats sum(OK)  by Date ID
| sort -Date

it returns results like this : 
DateIDOK
2020-09-30XXX123
2020-09-30YYY26
2020-09-29ZZZ763
2020-09-29XXX453

 

I want to retrieve only the last Date of each day but the only way to do that is by catching the last ID which is based on another timestamp. So I have a second request which retrieve the last ID : 

index="AAA" sourcetype=BBB

| stats max(Timestamp) as Timestamp by ID
| sort  Timestamp desc
| head 1

The result is : 

ID
XXX

I use a join command but I would like to know ik there is another way to create the search without the join.

Do you have a better solution ?

Thanks 

 

Labels (1)
Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index="AAA" sourcetype=BBB
| bin Date span=1d
| stats sum(OK) by Date ID
| eventstats latest(ID) as latestID
| where ID=latestID
| fields - latestID
| sort -Date

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
index="AAA" sourcetype=BBB
| bin Date span=1d
| stats sum(OK) by Date ID
| eventstats latest(Date) as latestDate by ID
| where Date=latestDate
| fields - latestDate
| sort -Date
0 Karma

mah
Builder

Hi, it does not work because :

- in the first query the timestamp is a field call "Date"

- in the second query the timestamp to get the last ID is "Timestamp" : the query must return just one ID 

Your search still returns events with not always the last ID : 

DateIDOK
2020-09-01XXX (latest)344
2020-09-30AAA867
2020-09-30XXX (latest)3473
2020-09-30BBB5387
2020-09-29BBB

772

2020-09-29XXX (latest)82

 

But what I want is a table like that :

DateIDOK
2020-09-01XXX (latest)344
2020-09-30XXX (latest)3473
2020-09-29XXX (latest)82
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index="AAA" sourcetype=BBB
| bin Date span=1d
| stats sum(OK) by Date ID
| eventstats latest(ID) as latestID
| where ID=latestID
| fields - latestID
| sort -Date

mah
Builder

Great ! It is exactly my need !

Thank you ! 

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...