Security

how to restrict a search to the last event per user

fabsi
New Member

I would like to know the number of users per application version over a period of time.

The events always include the application version and the user id but a user could have used different application versions over a period of time and I am interested on the latest, which happen to be the latest event for a given user, so how can I restrict a query to search only through the last events per user?, below it is my attempt which is not working..

search |stats values(email) as email, values(deviceSerial) as deviceSer, values(appVersion) as appVersion, latest(_time) AS latest_time by deviceSerial |fields email deviceSer appVersion latest_time| dedup email latest_time|  stats  dc(email) as users by appVersion | sort -users
0 Karma
1 Solution

rjthibod
Champion

Try this

search 
| stats max(_time) as latest_time by email appVersion
| stats dc(email) as users by appVersion 
| sort -users

View solution in original post

rjthibod
Champion

Try this

search 
| stats max(_time) as latest_time by email appVersion
| stats dc(email) as users by appVersion 
| sort -users

fabsi
New Member

I tried, but still users are counted twice if there are events done with multiple versions per user . So I managed to filter those cases using eventstats.. (there is usually a one to one relationship between deviceSerial and email fields)

search
| eventstats latest(_time) AS latest_time by deviceSerial
|dedup deviceSerial latest_time
| stats dc(email) as users by appVersion
| sort -users

0 Karma

fabsi
New Member

Hi, I am answering myself.. I decided to use eventstats. If somebody has another idea, please tell, specially if you think that the performance can be better..

search string| eventstats latest(_time) AS latest_time by deviceSerial |dedup deviceSerial latest_time|  stats  dc(email) as users by appVersion | sort -users

Seems to work..

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I believe you don't need both eventstats and dedup. I usually just use dedup when I need the latest event containing a particular field or set of fields.

---
If this reply helps you, Karma would be appreciated.
0 Karma

fabsi
New Member

will that be dedup deviceSerial then? and by definition will take the latest event?. thank you richgalloway and rjthibod

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...