Splunk Search

Aggregating by fields when not all events have the same fields

skippylou
Communicator

Trying to figure out how to aggregate with top when there are two field choices.

Here's an example of what I am trying:

Basically I have events that have either field1 OR field2. The events that have field1 also have a field called event1_type, the events that have field2 have a field called event2_type.

So I have the following search: (field1 > 5 OR field2 = 1). This works great. Normally if I was doing a single field search I would then '| top event_type'. Since the events have one of two event_type choices I'm not sure how to aggregate with top the event{1,2}_type values.

Any help is much appreciated.

Scott

Tags (2)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

I guess I would consider evaling a new field using coalesce():

field1 > 5 OR field2 = 1 | eval e_type=coalesce(event1_type,event2_type) | top e_type

If you're before 4.1, coalesce(x,y) is just if(isnotnull(x),x,y).

View solution in original post

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

I guess I would consider evaling a new field using coalesce():

field1 > 5 OR field2 = 1 | eval e_type=coalesce(event1_type,event2_type) | top e_type

If you're before 4.1, coalesce(x,y) is just if(isnotnull(x),x,y).

0 Karma

skippylou
Communicator

Thanks! That worked perfectly!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...