<?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: Combine results from subsearches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230825#M68452</link>
    <description>&lt;P&gt;You're correct, if you can filter the records, you should do that always. I updated the search which will do the filter and combine the results. Give that a try.&lt;/P&gt;</description>
    <pubDate>Fri, 06 May 2016 15:13:49 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-05-06T15:13:49Z</dc:date>
    <item>
      <title>Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230816#M68443</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I'm a newbie to Splunk so I'm hoping someone can assist me figuring out how to accomplish the following.  &lt;/P&gt;

&lt;P&gt;On a regular basis I have to search two sets of logs. I'd like to be able to knock it out in one go if possible while at the same time have the ability to display the results I need correctly.  &lt;/P&gt;

&lt;P&gt;The first search I run is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=network sourcetype=analysisFiles file_accessed="zip"  | stats  count by srcip, hostname, data
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which I then gather up the srcip and run the following search to gather the user information from another set of logs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=analysisFilesUserAccess srcip="src_ipFromAboveResults" | stats count by user, srcip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I figured out how to do a subsearch to pull the account information based on the results from the first search doing the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=analysisFilesUserAccess * [search index=network sourcetype=analysisFiles file_accessed="zip" | fields srcip |mvcombine delim=" OR " srcip | nomv srcip | rename srcip as search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem I'm running into and cant figure out is how to show results from both searches.  The subsearch only returns fields related to the second search and I can't seem to table or run stats based on the fields from the first.  Ideally what I'd like to be able to do is align the srcip from both searches and append the results from the first. I'd still like to be able to see the same results as running &lt;STRONG&gt;|count by srcip, hostname, data&lt;/STRONG&gt; but add the username by the matching srcip from both searches.  &lt;/P&gt;

&lt;P&gt;For example current results from each search when run independently looks as follows:&lt;/P&gt;

&lt;P&gt;First Search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  srcip        hostname     count
  192.168.1.49  hostName1       10
  192.168.1.98  hostName1       58
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Second Search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  user       srcip            count
  user01       192.168.1.49       10
  user02       192.168.1.98       58
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'd like the output to look like is one of the following two ways.  Key being that I just added the user results that I got back on a per IP basis.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  srcip        hostname      user     count
  192.168.1.49  hostName1     user01   10
  192.168.1.98  hostName1     user02   58

  srcip        hostname     count
  192.168.1.49  hostName1       10
  user01
  192.168.1.98  hostName1       58
  user02
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for all the help in advanced. &lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 12:19:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230816#M68443</guid>
      <dc:creator>ronaldsc</dc:creator>
      <dc:date>2016-05-04T12:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230817#M68444</link>
      <description>&lt;P&gt;How about this?:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; (index=network sourcetype=analysisFiles file_accessed="zip") OR (index=analysisFilesUserAccess) | stats  count by srcip, user, hostname, data
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2016 12:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230817#M68444</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-04T12:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230818#M68445</link>
      <description>&lt;P&gt;Thanks for the reply.  This pull every record that's in the second index and on top of that doesn't come back with any results.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 13:42:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230818#M68445</guid>
      <dc:creator>ronaldsc</dc:creator>
      <dc:date>2016-05-04T13:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230819#M68446</link>
      <description>&lt;P&gt;join command?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=analysisFilesUserAccess srcip="src_ipFromAboveResults" | stats count by user, srcip | join srcip [ search index=network sourcetype=analysisFiles file_accessed="zip"  | stats  count as count2 by srcip, hostname, data]&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 19:24:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230819#M68446</guid>
      <dc:creator>akheraj_splunk</dc:creator>
      <dc:date>2016-05-04T19:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230820#M68447</link>
      <description>&lt;P&gt;Remove the data field from the stats command.  I'm trying to avoid the join command due to its limitations.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 19:44:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230820#M68447</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-04T19:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230821#M68448</link>
      <description>&lt;P&gt;An but I need more work to my search still...&lt;/P&gt;

&lt;P&gt;Just use the join command as shown in the other answer for now.  I'll add some eval to the search I sent and revert later.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 19:47:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230821#M68448</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-04T19:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230822#M68449</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=analysisFilesUserAccess OR (index=network sourcetype=analysisFiles file_accessed="zip" ) | stats values(hostname) as hostname values(data) as data values(user) as user  count(eval(index="analysisFilesUserAccess")) as count1  count(eval(index="network")) as count1 values(index) as index by srcip | where mvcount(index)=2 | fields - index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update#1&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=analysisFilesUserAccess [search index=network sourcetype=analysisFiles file_accessed="zip" | stats count by src_ip | table src_ip ] ) OR (index=network sourcetype=analysisFiles file_accessed="zip" ) | stats values(hostname) as hostname values(data) as data values(user) as user  count(eval(index="analysisFilesUserAccess")) as count1  count(eval(index="network")) as count1 values(index) as index by srcip | where mvcount(index)=2 | fields - index
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2016 20:17:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230822#M68449</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-04T20:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230823#M68450</link>
      <description>&lt;P&gt;No go as well.  Maybe I'm not following but I don't understand by looking through an entire index is the recommended way to do this.  Instead wouldn't it be better to just pass the specific data you want to be searched to the second search?  Is there no good way to combine the results from the second search with data from the first?  &lt;/P&gt;

&lt;P&gt;When I add mvcombine delim=" OR " srcip this gives me the specific data I need to search which looks through a couple thousand records vs. doing index=analysiFileUserAccess which seems to pull through everything in the index?  Sorry if I'm not following, just trying to make sure I understand how it's actually working under the hood. &lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 14:56:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230823#M68450</guid>
      <dc:creator>ronaldsc</dc:creator>
      <dc:date>2016-05-06T14:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230824#M68451</link>
      <description>&lt;P&gt;This only works if i manually add the  src_ip.  I'm hoping to pass the results from the first search to the second automatically.&lt;/P&gt;

&lt;P&gt;For example:&lt;BR /&gt;
In my original search by doing a &lt;STRONG&gt;|mvcombine delim=" OR " srcip | nomv srcip&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I get this which is in turn passed to the first search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;192.168.1.49 OR 192.168.1.52 OR 192.168.1.88 OR 192.168.1.214
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which then searches for that data by running the second search &lt;STRONG&gt;index=analysisFilesUserAccess  192.168.1.49 OR 192.168.1.52 OR 192.168.1.88 OR 192.168.1.214&lt;/STRONG&gt;*.  Where I am stuck is how do I go about combining fields from the first result with the second.  There are fields from both that I'd like to group together.  The minute I add |stats or anything else to the first search it seems to kill the passing of these IP values.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 15:03:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230824#M68451</guid>
      <dc:creator>ronaldsc</dc:creator>
      <dc:date>2016-05-06T15:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230825#M68452</link>
      <description>&lt;P&gt;You're correct, if you can filter the records, you should do that always. I updated the search which will do the filter and combine the results. Give that a try.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 15:13:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230825#M68452</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-06T15:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Combine results from subsearches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230826#M68453</link>
      <description>&lt;P&gt;Thanks for the continued help, somesoni2.   &lt;/P&gt;

&lt;P&gt;When I run the search it always comes back with just results from 1 index.  When I run each of the searches independently I get the results I'm looking for.&lt;/P&gt;

&lt;P&gt;If I run the searches below they each return events (this is just your search broken out).  The first search has the index of analysisFilesUserAccess and the second search has the index index of network.  However, when I run both combined the results only has 1 index returned.  Not sure why and this is causing no result returned.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; **(index=analysisFilesUserAccess [search index=network sourcetype=analysisFiles file_accessed="zip" | stats count by src_ip | table src_ip ] )**

 **(index=network sourcetype=analysisFiles file_accessed="zip" ) | stats values(hostname) as hostname values(data) as data 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I look at the job inspector is get the message saying &lt;STRONG&gt;verify that the fields expected by the report commands are present in the events&lt;/STRONG&gt; for the two fields that are supposed to come from the network index.  &lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2016 14:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-results-from-subsearches/m-p/230826#M68453</guid>
      <dc:creator>ronaldsc</dc:creator>
      <dc:date>2016-05-09T14:35:28Z</dc:date>
    </item>
  </channel>
</rss>

