<?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: How to combine two indexes with Stats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476698#M143374</link>
    <description>&lt;P&gt;Hi mattfunk20,&lt;/P&gt;

&lt;P&gt;you need to get the unique identifier from both indexes and use it in the &lt;CODE&gt;stats by&lt;/CODE&gt; clause. I assume that &lt;CODE&gt;dest_mac&lt;/CODE&gt; and &lt;CODE&gt;mac_address&lt;/CODE&gt; are theses fields, so try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=Index1 sourcetype=Type1) OR (index=Index2)
| fields field1 field 2 mac_address dest_mac 
| eval mac_address=replace(mac_address,"\W","") 
| eval mac_address=lower(mac_address) 
| rex field=dest_nt_host "(?[^.]+)."
| eval dest_nt_host=lower(dest_nt_host) 
| eval dest_mac=lower(dest_mac)
| eval mac=case(isnotnull(dest_mac), dest_mac, isnotnull(mac_address), mac_address, 1=1, "unknown")
| stats values(index) as index values(field1) as field1 values(field2) as field 2 values(index) as index values(mac_address) by mac 
| table mac mac_address field 1 field 2 index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Might need some tweaking but I'm sure you get what I mean &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;And thanks for finding my original post helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
    <pubDate>Thu, 20 Feb 2020 02:41:42 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2020-02-20T02:41:42Z</dc:date>
    <item>
      <title>How to combine two indexes with Stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476697#M143373</link>
      <description>&lt;P&gt;Following a super helpful thread here &lt;A href="https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html" target="_blank"&gt;https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt;&lt;BR /&gt;
But I've ran into an issue where when I start to use stats, I always drop one of my indexes, is it possible to use stats and still maintain both indexes, or at least merge the data prior to losing one of them?&lt;/P&gt;

&lt;P&gt;(index=Index1 sourcetype=Type1) OR (index=Index2)&lt;BR /&gt;
| fields field1 field 2 mac_address  dest_mac &lt;BR /&gt;
| eval mac_address=replace(mac_address,"\W","") &lt;BR /&gt;
| eval mac_address=lower(mac_address) &lt;BR /&gt;
| rex field=dest_nt_host "(?[^.]+)."&lt;BR /&gt;
| eval dest_nt_host=lower(dest_nt_host) &lt;BR /&gt;
| eval dest_mac=lower(dest_mac)&lt;BR /&gt;
| stats values(index) as index values(field1) as field1 values(field2) as field 2 values(index) as index values(mac_address) by dest_mac &lt;BR /&gt;
| table dest_mac mac_address field 1 field 2 index&lt;/P&gt;

&lt;P&gt;essentially whatever state with the BY-clause is the index that's kept, but ideally I'd like to match on dest_mac and mac_address, while pulling field 1 from index 1, and field 2 from index 2&lt;BR /&gt;
Without the by clause, my data essentially is appending without append, looking like...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;field 1 dest_mac index 1

                                            field 2 mac_Address index 2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advanced!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:17:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476697#M143373</guid>
      <dc:creator>mattfunk20</dc:creator>
      <dc:date>2020-09-30T04:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two indexes with Stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476698#M143374</link>
      <description>&lt;P&gt;Hi mattfunk20,&lt;/P&gt;

&lt;P&gt;you need to get the unique identifier from both indexes and use it in the &lt;CODE&gt;stats by&lt;/CODE&gt; clause. I assume that &lt;CODE&gt;dest_mac&lt;/CODE&gt; and &lt;CODE&gt;mac_address&lt;/CODE&gt; are theses fields, so try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=Index1 sourcetype=Type1) OR (index=Index2)
| fields field1 field 2 mac_address dest_mac 
| eval mac_address=replace(mac_address,"\W","") 
| eval mac_address=lower(mac_address) 
| rex field=dest_nt_host "(?[^.]+)."
| eval dest_nt_host=lower(dest_nt_host) 
| eval dest_mac=lower(dest_mac)
| eval mac=case(isnotnull(dest_mac), dest_mac, isnotnull(mac_address), mac_address, 1=1, "unknown")
| stats values(index) as index values(field1) as field1 values(field2) as field 2 values(index) as index values(mac_address) by mac 
| table mac mac_address field 1 field 2 index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Might need some tweaking but I'm sure you get what I mean &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;And thanks for finding my original post helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 02:41:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476698#M143374</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2020-02-20T02:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two indexes with Stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476699#M143375</link>
      <description>&lt;P&gt;Super cool to see the same person help me out again. &lt;BR /&gt;
Thanks, worked quite well!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 17:45:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-indexes-with-Stats/m-p/476699#M143375</guid>
      <dc:creator>mattfunk20</dc:creator>
      <dc:date>2020-02-21T17:45:26Z</dc:date>
    </item>
  </channel>
</rss>

