<?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 Add count of subsearch results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355994#M105322</link>
    <description>&lt;P&gt;I need to return all rows from my top search but add a count of rows from a map or subquery/subsearch.  &lt;/P&gt;

&lt;P&gt;In my system I have a number of batches which may have a number of errors that exist in a different index and I want to display a count of those errors (even if zero) alongside the batch.&lt;/P&gt;

&lt;P&gt;Something like this pseudo query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=A | fields batch_id, batch_name | count = COUNT("search index=B batch_id=$batch_id$ level=error")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is to display on a dashboard in a stats table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Id     Name     Errors
 1234 | BatchA | 0
 4567 | BatchB | 6
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Sep 2017 10:02:49 GMT</pubDate>
    <dc:creator>LittleColin</dc:creator>
    <dc:date>2017-09-23T10:02:49Z</dc:date>
    <item>
      <title>Add count of subsearch results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355994#M105322</link>
      <description>&lt;P&gt;I need to return all rows from my top search but add a count of rows from a map or subquery/subsearch.  &lt;/P&gt;

&lt;P&gt;In my system I have a number of batches which may have a number of errors that exist in a different index and I want to display a count of those errors (even if zero) alongside the batch.&lt;/P&gt;

&lt;P&gt;Something like this pseudo query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=A | fields batch_id, batch_name | count = COUNT("search index=B batch_id=$batch_id$ level=error")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is to display on a dashboard in a stats table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Id     Name     Errors
 1234 | BatchA | 0
 4567 | BatchB | 6
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Sep 2017 10:02:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355994#M105322</guid>
      <dc:creator>LittleColin</dc:creator>
      <dc:date>2017-09-23T10:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Add count of subsearch results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355995#M105323</link>
      <description>&lt;P&gt;Hi LittleColin,&lt;BR /&gt;
if you have batch_name in both the indexes, you can try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=B [ search index=A | dedup batch_id| fields batch_id ]
| stats values(batch_name) AS batch_name count AS Errors by batch_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if instead you have batch_name only in index=A, you can try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=B
| stats count AS Errors by batch_id
| join type=left batch_id [ search index=B | fields batch_id batch_name]
| table batch_id batch_name Errors
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The second one is less performant than the first.&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 10:44:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355995#M105323</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-09-23T10:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add count of subsearch results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355996#M105324</link>
      <description>&lt;P&gt;Many thanks for the swift reply - for me your second option is working well&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 20:29:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Add-count-of-subsearch-results/m-p/355996#M105324</guid>
      <dc:creator>LittleColin</dc:creator>
      <dc:date>2017-09-23T20:29:47Z</dc:date>
    </item>
  </channel>
</rss>

