Splunk Search

How to edit my search to select the newest event based on LastModTime field?

joesrepsol
Path Finder

So I'm taking in data from a source that has some duplicate records for the same ID. The only differentiator between events is a "LastModTime" field value, which is an integer. larger number means most recent change.

So I'm trying to write a Splunk search to get all the events from this data source, and where multiple ID exists, only give me the most recent event (i.e. LastModTime is the largest value). Sounded so easy to say, but proving to be a challenge with mvindex command and now I'm stumped.

ID LastModTime Counter
108 1495147243 1
109 1495152331 1
110 1495207972 1
111 1495205705 1
112 1495207542 1
113 1495209093 1 I only want this event out of all the ID=113 events
113 1495217660 1
113 1495218310 1
113 1495222596 1

114 1495211855 1
115 1495212746 1

help?

0 Karma

somesoni2
Revered Legend

Assuming that your _time value is setup based on LastModTime field and you get one ID in one event/row, try this

your base search | dedup ID

It should keep only the latest record for every ID if it appears more that once.

If your _time field is not based on LastModTime field, try this

yourbase search | sort 0 ID -LastModTime | dedup ID

joesrepsol
Path Finder

That worked perfect! Thank you!

yourbase search | sort 0 ID -LastModTime | dedup ID

0 Karma
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...