Splunk Search

How to work on the latest event only?

zacksoft
Contributor

I have my query ready which essentially extracts some fields and displays in a table.
But I want to work on the latest event only.
How do I put condition so that my query only works on the latest one event?

Tags (1)
0 Karma
1 Solution

493669
Super Champion

try head command:
Returns the first N number of specified results in search order

... | head 1

View solution in original post

0 Karma

harishalipaka
Motivator
|sort _time |head 1
Thanks
Harish

zacksoft
Contributor

Is |sort _time necessary ?
Won't |head 1 alone will do the job?
Just confirming.

0 Karma

harishalipaka
Motivator

If it is realtime data it will come updated with head 1 ..or it is saved data it will directly give top of the value head 1 in this situation you have to sort _time than you will get top value as updated.

Thanks
Harish
0 Karma

493669
Super Champion

even if there are duplicates, using head 1 it will took latest one

0 Karma

harishalipaka
Motivator

below example explain how it is works .

| makeresults 
| eval A=45 
| eval DateHour="2018-06-06 18:47:22.820" 
| append 
    [| makeresults 
| eval A=30 
| eval DateHour="2018-06-06 18:45:22.820" ] 
| append 
    [| makeresults 
| eval A=50 
| eval DateHour="2018-06-06 18:57:22.000" ]  
| fields - _time
| head 1
Thanks
Harish
0 Karma

493669
Super Champion

try head command:
Returns the first N number of specified results in search order

... | head 1
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...