<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Matching fields from different indices to return another field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470364#M132345</link>
    <description>&lt;P&gt;Interesting! I tried running your query and while it gives me DeviceName and Owner properly, none of the other fields (FileName) are blank. Any idea why?&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jun 2020 14:45:46 GMT</pubDate>
    <dc:creator>izyknows</dc:creator>
    <dc:date>2020-06-03T14:45:46Z</dc:date>
    <item>
      <title>Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470361#M132342</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have two different indexes where I need to match a field and if true, return another field.&lt;/P&gt;
&lt;P&gt;First Search (Index1)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;FileName          DeviceName
explorer.exe     myserver.test.com
processor.dll    anothersystem.xyz.abc
third.exe        yetanother.aaa.bbb
another.exe      myserver.test.com
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second search (Index2)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;HostName                      Owner
MYserver.test.com        bob@sample.com
nonEXistent.abc.ccc      larry@sample.com
yetANOTHER.aaa.bbb       charlie@sample.com
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired search result&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;DeviceName                    FileName                Owner
myserver.test.com            explorer.exe           bob@sample.com
                             another.exe
yetanother.aaa.bbb           third.exe              charlie@sample.com
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Couple of things to notice&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I need to show results where DeviceName and HostName match. Both fields may be in different case (so case insensitive matching is required)&lt;/LI&gt;
&lt;LI&gt;If DeviceName==HostName, I need the Owner field returned from Index2&lt;/LI&gt;
&lt;LI&gt;One DeviceName/HostName may have many FileNames under it and I need to display all (explorer.exe + another.exe)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I've been tinkering around and am having a hard time finding the right query. Here's where I'm at.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;(index=index1 sourcetype=type1 FileName=somecondition*) OR (index=index2 sourcetype=type2)
| fields FileName, DeviceName, Owner, HostName
| eval magic=case(DeviceName==HostName, Owner)
| stats list(FileName) as FileName, list(magic) as SysOwner by DeviceName
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although it doesn't work. I tried variations of the eval statement using &lt;CODE&gt;if&lt;/CODE&gt;, &lt;CODE&gt;coalesce&lt;/CODE&gt; and a few other solutions from other questions. But I believe the case difference between the two fields is what is hindering me.&lt;/P&gt;
&lt;P&gt;I'm still new to Splunk and any help would be appreciated! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 17:25:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470361#M132342</guid>
      <dc:creator>izyknows</dc:creator>
      <dc:date>2020-06-08T17:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470362#M132343</link>
      <description>&lt;P&gt;@izyknows Please try below-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|eval DeviceName=coalesce(DeviceName,HostName)|stats values(FileName) as FileName values(Owner) as Owner by DeviceName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is using sample data-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval FileName="explorer.exe", DeviceName="myserver.test.com"
|append[|makeresults|eval HostName="myserver.test.com", Owner="bob@sample.com"]
|append[|makeresults|eval FileName="another.exe", DeviceName="myserver.test.com"]
|fields - _time|eval DeviceName=coalesce(DeviceName,HostName)|stats values(FileName) as FileName values(Owner) as Owner by DeviceName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 12:49:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470362#M132343</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2020-06-03T12:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470363#M132344</link>
      <description>&lt;P&gt;You were close.  The secret is to create a common field between the two indexes that Splunk can use to match up events.  I like to use &lt;CODE&gt;coalesce&lt;/CODE&gt; to do that.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=index1 sourcetype=type1 FileName=somecondition*) OR (index=index2 sourcetype=type2)
 | fields FileName, DeviceName, Owner, HostName
 | eval DeviceName=coalesce(DeviceName, HostName)
 | stats values(*) as * by DeviceName
 | table DeviceName FileName Owner
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 12:54:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470363#M132344</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-03T12:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470364#M132345</link>
      <description>&lt;P&gt;Interesting! I tried running your query and while it gives me DeviceName and Owner properly, none of the other fields (FileName) are blank. Any idea why?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 14:45:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470364#M132345</guid>
      <dc:creator>izyknows</dc:creator>
      <dc:date>2020-06-03T14:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470365#M132346</link>
      <description>&lt;P&gt;Thanks! I tried out your query but no luck. Similar to the other answer, DeviceName and Owner populate fine but the other fields are blank. &lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 14:46:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470365#M132346</guid>
      <dc:creator>izyknows</dc:creator>
      <dc:date>2020-06-03T14:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470366#M132347</link>
      <description>&lt;P&gt;The example query works fine for me.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 17:29:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470366#M132347</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-03T17:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470367#M132348</link>
      <description>&lt;P&gt;Unfortunately it doesn't for me. The example I posted is a simplified version of the actual scenario though. There are 3 more fields from each index which I also fetch and show in the end. I took them out for the sake of simplicity.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 15:12:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470367#M132348</guid>
      <dc:creator>izyknows</dc:creator>
      <dc:date>2020-06-04T15:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470368#M132349</link>
      <description>&lt;P&gt;I think when stats values() comes into picture, it removes duplicates. And in my FolderPath and other fields, I may have (and want) these duplicates. Why is it that after coalesce, my other fields disappear? &lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 15:28:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/470368#M132349</guid>
      <dc:creator>izyknows</dc:creator>
      <dc:date>2020-06-04T15:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Matching fields from different indices to return another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/503653#M140607</link>
      <description>&lt;P&gt;Yes, &lt;FONT face="courier new,courier"&gt;stats values(foo)&lt;/FONT&gt;&amp;nbsp;removes the duplicate values of field foo. To see the duplicates use &lt;FONT face="courier new,courier"&gt;list(foo)&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;Coalesce should not be affecting your other fields.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 00:41:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Matching-fields-from-different-indices-to-return-another-field/m-p/503653#M140607</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-10T00:41:06Z</dc:date>
    </item>
  </channel>
</rss>

