Splunk Search

If I have 2 different fields that match in 2 indexes, how do I return and merge fields from both indexes?

lhanich1
Path Finder

I have googled and searched my little heart out, but I am unsure if I am querying using best practice or if this would even work. But here is what I am trying to do:

Use case example:
AV alert logs to one index, with identifiable field "Computer_Name" then ensure "src_host" field matches "Computer_Name" in another index and then stats various fields within each index.

index=index2 sourcetype=irrelevant2 category!=Other 
| fields Computer_Name, field, field 
[search index=index1 ind_primary_user_business_unit=irrelevant | fields src_host, field, field, field, field, field, field]
| eval host=coalesce(src_host,Computer_Name)
|stats count by host, field from index 1, field from index 1,field from index 2, field from index 2, field from index 2, field from index 2, field from index 2, field from index 2

Thanks as always

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

This is basically https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-jo...

In your case, something like this:

(index=index2 sourcetype=irrelevant2 category!=Other) OR (index=index1 ind_primary_user_business_unit=irrelevant)
| fields Computer_Name, field, field, src_host, field, field, field, field, field, field
| eval combined_host=coalesce(src_host,Computer_Name)
| stats count first(field1) as field1 first(field2) as field2 ... by combined_host

That's assuming each fieldN value is unique / exists only once / you only want one value per host. If you have multiple values for each fieldN, and want multiple result rows, you'll need to provide more details on how that split should happen / how the various events from each index should be linked together.

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

This is basically https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-jo...

In your case, something like this:

(index=index2 sourcetype=irrelevant2 category!=Other) OR (index=index1 ind_primary_user_business_unit=irrelevant)
| fields Computer_Name, field, field, src_host, field, field, field, field, field, field
| eval combined_host=coalesce(src_host,Computer_Name)
| stats count first(field1) as field1 first(field2) as field2 ... by combined_host

That's assuming each fieldN value is unique / exists only once / you only want one value per host. If you have multiple values for each fieldN, and want multiple result rows, you'll need to provide more details on how that split should happen / how the various events from each index should be linked together.

0 Karma

lhanich1
Path Finder

Thank you, clearly I was overthinking!

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...