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

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...