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!

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

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

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