Splunk Search

Need to dedup results based on id only if the field is not empty

anthonycopus
Path Finder

Hi,

I need help deduplicating in a search where only half the data contains an id. Basically, the old data has a field ses_id : "" whilst the new data will be populated ses_id : "123"

The search ends up with a table where we need a count which only deduplicates the entries which have a number in the ses_id field. A normal dedup is not good enough as it will count all the entries with "" as a single one obviously.

My search is as follows:

index="testindex" app="testapp" action="view" | stats count as views, max(_time) as _time by name

Any help would be appreciated,

Thanks

1 Solution

anthonycopus
Path Finder

Found an easy fix by changing the field populated with "" to null using the following search in total:

index="testindex" app="testapp" action="view" | eval ses_id=nullif(ses_id,"") | dedup ses_id keepempty=true | stats count as views, max(_time) as _time by name

Changing the field to null is there was no entry meant the keepempty property in the dedup can be used successfully

View solution in original post

anthonycopus
Path Finder

Found an easy fix by changing the field populated with "" to null using the following search in total:

index="testindex" app="testapp" action="view" | eval ses_id=nullif(ses_id,"") | dedup ses_id keepempty=true | stats count as views, max(_time) as _time by name

Changing the field to null is there was no entry meant the keepempty property in the dedup can be used successfully

nick405060
Motivator

tl;dr keepempty=true

I have no idea how I have used Splunk for this long and not known about this. Thanks.

0 Karma

anthonycopus
Path Finder

Thanks, in the end I found a cleaner alternative:

| eval ses_id=nullif(ses_id,"") | dedup ses_id keepempty=true

Changing the "" in the field to null meant I could use the keepempty function in the search

lukejadamec
Super Champion

You could try to search for ses_id is not null, dedup the results, and then join a second search that finds those ses_id that are null.

There is not enough info to tell you what field to join on.

0 Karma
Get Updates on the Splunk Community!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...