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
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

  🚀 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 ...