<?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: Sub Searching multiple indexes and sourcetypes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471806#M132747</link>
    <description>&lt;P&gt;Welp. looks like @gcusello beat me to the answer &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2019 12:22:00 GMT</pubDate>
    <dc:creator>arjunpkishore5</dc:creator>
    <dc:date>2019-10-30T12:22:00Z</dc:date>
    <item>
      <title>Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471802#M132743</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;

&lt;P&gt;I would like a little help with a query I am having difficulty with. The objective to leverage sub searching to combine searches from 2 different indexes and sourcetypes. There are no 1 to 1 field mappings between the data sets so there is some renaming involved but I don't this should impact the end result.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Search 1&lt;/STRONG&gt;&lt;BR /&gt;
index="index A" sourcetype="sourcetype A" "icmp" | rename id.resp_h as Destination_Host | search (Destination_Host!=10.0.0.0/8 AND Destination_Host!=172.16.0.0/12 AND Destination_Host!=xxx.xxx.0.0/16 AND Destination_Host!=xxx.xxx.0.0/16 AND &lt;BR /&gt;
Destination_Host!=xxx.xxx.*) | where (orig_ip_bytes &amp;gt; 1000 AND orig_bytes &amp;gt; 1000) | rename id.orig_h as Source_IP | stats count earliest(_time) as earliest latest(_time) as latest by Source_IP, Destination_Host | eval isOutlier=if(earliest &amp;gt;= relative_time(now(), "-1d@d"), 1, 0) | where isOutlier=1 | convert ctime(earliest) ctime(latest)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Output&lt;/STRONG&gt;&lt;BR /&gt;
Source_IP            Destination_Host   count   earliest                                                       latest                                                isOutlier&lt;BR /&gt;
xxx.xxx.xxx.xx  52.112.3.145                      1         10/29/2019  13:30:52.881125            10/29/2019 13:30:52.881125           1&lt;BR /&gt;
xxx.xxx.xxx.xx  205.185.216.10            1         10/29/2019 08:42:51.725199             10/29/2019 08:42:51.725199           1&lt;BR /&gt;
xxx.xxx.xxx.xx  8.247.48.126                      1         10/29/2019 03:43:12.544464             10/29/2019 03:43:12.544464           1&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Search 2&lt;/STRONG&gt;&lt;BR /&gt;
index="index B" sourcetype="sourcetype B" description=Assign OR description=Renew | rename ip as Source_IP, mac as "Mac Address", nt_host as Source_Host | dedup "Mac Address" | table Source_IP, Source_Host, "Mac Address"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Output&lt;/STRONG&gt;&lt;BR /&gt;
Source_IP          Source_Host          Mac Address&lt;BR /&gt;
xxx.xxx.xxx.xx  xxxxxxx                 xxxxxxxxx&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Combined Search&lt;/STRONG&gt;&lt;BR /&gt;
index="index 2" sourcetype="sourcetype 2" description=Assign OR description=Renew | rename ip as Source_IP, mac as "Mac Address", nt_host as Host | table Source_IP, "Mac Address", Host&lt;BR /&gt;
| join Source_IP&lt;BR /&gt;
[search index=index 1 sourcetype="sourcetype 2" "icmp" | rename id.resp_h as Destination_Host | search (Destination_Host!=10.0.0.0/8 AND Destination_Host!=xxx.xxx.0.0/12 AND Destination_Host!=xxx.xxx.0.0/16 AND Destination_Host!=xxx.xxx.0.0/16 AND Destination_Host!=xxx.xxx.*) | where (orig_ip_bytes &amp;gt; 1000 AND orig_bytes &amp;gt; 1000) | rename id.orig_h as Source_IP | stats count earliest(_time) as earliest latest(_time) as latest by Source_IP, Destination_Host | eval isOutlier=if(earliest &amp;gt;= relative_time(now(), "-1d@d"), 1, 0) | where isOutlier=1 | convert ctime(earliest) ctime(latest)]&lt;BR /&gt;
| dedup "Mac Address"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Desired Output with combined data&lt;/STRONG&gt;&lt;BR /&gt;
Source_IP        Source_Host  Mac Address  Destination_Host count   earliest                              latest                                     isOutlier&lt;BR /&gt;
xxx.xxx.xxx.xx    ABC Host        xx:xx:xx          52.112.3.145               1            10/29/2019 12:30      10/29/2019 13:30                    1&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;instead getting this output with only search 2 data&lt;/STRONG&gt;&lt;BR /&gt;
Source_IP        Source_Host  Mac Address  Destination_Host count   earliest                              latest                                     isOutlier&lt;BR /&gt;
xxx.xxx.xxx.xx    ABC Host        xx:xx:xx          52.112.3.145               1            10/29/2019 12:30      10/29/2019 13:30                    1&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:46:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471802#M132743</guid>
      <dc:creator>jj39501</dc:creator>
      <dc:date>2020-09-30T02:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471803#M132744</link>
      <description>&lt;P&gt;The desired output and actual output looks exactly the same. Did you intend to post a different dataset ?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 11:58:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471803#M132744</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-10-30T11:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471804#M132745</link>
      <description>&lt;P&gt;Hi  jj39501,&lt;BR /&gt;
at first you don't need to use search and where commands after a nother search command, you can put all the search parameters in the main search and you'll have a more performant search.&lt;BR /&gt;
So your first search could be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index A" sourcetype="sourcetype A" "icmp" (id.resp_h!=10.0.0.0/8 id.resp_h!=172.16.0.0/12 id.resp_h!=xxx.xxx.0.0/16 id.resp_h!=xxx.xxx.0.0/16 id.resp_h!=xxx.xxx.*) (orig_ip_bytes &amp;gt; 1000 orig_bytes &amp;gt; 1000) 
| rename id.resp_h as Destination_Host id.orig_h as Source_IP 
| stats count earliest(_time) as earliest latest(_time) as latest by Source_IP, Destination_Host 
| eval isOutlier=if(earliest &amp;gt;= relative_time(now(), "-1d@d"), 1, 0) 
| where isOutlier=1 
| convert ctime(earliest) ctime(latest)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For the combined, I hint to not use join command that's very slow and it has the limit of 50,000 results for the subsearch, so try a different approach like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="index A" sourcetype="sourcetype A" "icmp" (id.resp_h!=10.0.0.0/8 id.resp_h!=172.16.0.0/12 id.resp_h!=xxx.xxx.0.0/16 id.resp_h!=xxx.xxx.0.0/16 id.resp_h!=xxx.xxx.*) (orig_ip_bytes &amp;gt; 1000 orig_bytes &amp;gt; 1000) ) OR (index="index B" sourcetype="sourcetype B" description=Assign OR description=Renew)
| rename id.resp_h as Destination_Host id.orig_h as Source_IP  ip as Source_IP mac as "Mac Address" nt_host as Source_Host 
| stats count earliest(_time) AS earliest latest(_time) AS latest values(Destination_Host ) AS Destination_Host values("Mac Address") AS "Mac Address" BY Source_IP
 | dedup "Mac Address"
| stats count earliest(_time) AS earliest latest(_time) AS latest values("Mac Address") AS "Mac Address" values(Source_Host) AS Source_Host BY Source_IP Destination_Host 
| eval isOutlier=if(earliest &amp;gt;= relative_time(now(), "-1d@d"), 1, 0) 
| where isOutlier=1 
| convert ctime(earliest) ctime(latest)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The approach is: to put in the main search both the searches and connect them using stats command by the join key.&lt;BR /&gt;
If I forgot some field, please sorry me and add it using values option.&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 12:00:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471804#M132745</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-10-30T12:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471805#M132746</link>
      <description>&lt;P&gt;I have combined your 2 searches into one. However, I have no way of testing since I do not have the base data. Try this out and let me know if this works.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="index 2" sourcetype="sourcetype 2" description=Assign OR description=Renew) OR (index=index 1 sourcetype="sourcetype 2" "icmp" NOT ip.resp_h IN ("10.0.0.0/8", "xxx.xxx.*") ) 
| rename ip as Source_IP, mac as "Mac Address", nt_host as Source_Host , id.resp_h as Destination_Host, id.orig_h as Source_IP_2 
| fillnull Destination_Host value="Unknown" 
| eval Source_IP=coalesce(Source_IP, if((orig_ip_bytes &amp;gt; 1000 AND orig_bytes &amp;gt; 1000), Source_IP_2, null())) 
| stats count(eval(if(index=="index 1", Source_IP, null()))) as total_count, min(eval(if(index=="index 1", _time, null()))) as earliest, max(eval(if(index=="index 1", _time, null()))) as latest, values(mac) as "Mac Address", values(Source_Host) as Source_Host by Source_IP, Destination_Host 
| eval Destination_Host=if(Destination_Host=="Unknown", null(), Destination_Host) 
| eval isOutlier=if(earliest &amp;gt;= relative_time(now(), "-1d@d"), 1, 0) 
| stats max(*) as * by Source_IP 
| where isOutlier=1 
| convert ctime(earliest) ctime(latest)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 12:19:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471805#M132746</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-10-30T12:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471806#M132747</link>
      <description>&lt;P&gt;Welp. looks like @gcusello beat me to the answer &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 12:22:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471806#M132747</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-10-30T12:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471807#M132748</link>
      <description>&lt;P&gt;Giuseppe,&lt;/P&gt;

&lt;P&gt;Thank you for your time and willingness to help with this search. I tried your suggestion and unfortunately there seems to be in issue in the second stats command that I can't figure out. As is, I get the raw event data just fine. However the statistics are not being applied. Removing the second stats command gives me statistical data but only it looks like it only being applied to index B.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 07:49:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471807#M132748</guid>
      <dc:creator>jj39501</dc:creator>
      <dc:date>2019-11-02T07:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471808#M132749</link>
      <description>&lt;P&gt;Not quite. ha!&lt;/P&gt;

&lt;P&gt;I do appreciate you looking at this for me. I tried your search as well, however I am getting the following error. Thoughts!&lt;/P&gt;

&lt;P&gt;Error in 'stats' command: You must specify a rename for the aggregation specifier on the dynamically evaluated field 'count(eval(if(index=="index 1", Source_IP, null())))'.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 07:55:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471808#M132749</guid>
      <dc:creator>jj39501</dc:creator>
      <dc:date>2019-11-02T07:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471809#M132750</link>
      <description>&lt;P&gt;Hi jj39501,&lt;BR /&gt;
Please try again, I did a copy error!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="index A" sourcetype="sourcetype A" "icmp" (id.resp_h!=10.0.0.0/8 id.resp_h!=172.16.0.0/12 id.resp_h!=xxx.xxx.0.0/16 id.resp_h!=xxx.xxx.0.0/16 id.resp_h!=xxx.xxx.*) (orig_ip_bytes &amp;gt; 1000 orig_bytes &amp;gt; 1000) ) OR (index="index B" sourcetype="sourcetype B" description=Assign OR description=Renew)
| rename id.resp_h as Destination_Host id.orig_h as Source_IP  ip as Source_IP mac as "Mac Address" nt_host as Source_Host 
| stats count earliest(_time) AS earliest latest(_time) AS latest values(Destination_Host ) AS Destination_Host values("Mac Address") AS "Mac Address" values(Source_Host) AS Source_Host BY Source_IP
| dedup "Mac Address"
| stats count earliest(_time) AS earliest latest(_time) AS latest values("Mac Address") AS "Mac Address" values(Source_Host) AS Source_Host BY Source_IP Destination_Host 
| eval isOutlier=if(earliest &amp;gt;= relative_time(now(), "-1d@d"), 1, 0) 
| where isOutlier=1 
| convert ctime(earliest) ctime(latest)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If there is still a problem, please debug it and check what are the fields after the first stats.&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 10:26:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471809#M132750</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-11-02T10:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471810#M132751</link>
      <description>&lt;P&gt;@jj39501 Edited my original answer with corrections. Please try now. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 11:40:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471810#M132751</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-02T11:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sub Searching multiple indexes and sourcetypes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471811#M132752</link>
      <description>&lt;P&gt;Thanks for the feedback. I am no longer getting the error message. However my output is still omitting the Source_Host and MAC Address fields/data.&lt;/P&gt;

&lt;P&gt;When I run the search up until the first stats command, the MAC Address and Source_Host fields show up, but they are blank.  Thoughts?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 10:40:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sub-Searching-multiple-indexes-and-sourcetypes/m-p/471811#M132752</guid>
      <dc:creator>jj39501</dc:creator>
      <dc:date>2019-11-14T10:40:37Z</dc:date>
    </item>
  </channel>
</rss>

