Splunk Search

How to compare fields of two different events and if they match how to show the event count ?

jhonsonkelly56
New Member

Eg : Event 1 : Field1, Field a, Field b
Event 2 : Field2, Fields n, Field y

How to compare Field1 of event 1 and Field2 of event2 and output put the matching event count.

Tags (2)
0 Karma

woodcock
Esteemed Legend

Assuming that there is one event that is at the end that indicates "session/transaction complete" and that your "joiner" field is host, you do it like this:

(index=source1 AND sourcetype=source1) OR (index=source2 AND sourcetype=source2)
| streamstats count(eval(searchmatch("session/transaction complete"))) AS sessionID BY host
| stats values(*) AS * BY sessionID host
| stats count AS total_session_count count(eval(Field1==Field2)) AS match_count BY host
0 Karma

woodcock
Esteemed Legend

If you have a "session/transaction start" event, then do a | reverse at the top.

0 Karma

woodcock
Esteemed Legend

Like this:

(index=source1 AND sourcetype=source1) OR (index=source2 AND sourcetype=source2)
| stats count AS total_event_count count(eval(Field1==Field2)) AS match_count BY <some joiner field, like host>
0 Karma

jhonsonkelly56
New Member

Thank you @woodcock that was fantastic. I have another question, what in the above scenario what if the events come from same index and source. How do I compare field(field 1 and field2) from different events.

0 Karma

woodcock
Esteemed Legend

This answer is wrong; see my new answer.

0 Karma
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...