<?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 keep results with a count of 0 in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556061#M157893</link>
    <description>&lt;P&gt;If you want to keep the cart details (outer search) where the inner search (items) does not have any items for the station number, then you should use an outer/left join, i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| join type=left station_number [...]&lt;/LI-CODE&gt;&lt;P&gt;and then you need to do what you want to do with last_item_time and item_count to either leave those as null or put in some default value, e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fillnull value=0 item_count&lt;/LI-CODE&gt;&lt;P&gt;by the way, your inner search is doing this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;search index=INDEX host=HOSTNAME sourcetype=SOURCETYPE
| rex field=_raw "Move\sItem-(?&amp;lt;item&amp;gt;\w+\-\d+\-\d+\-\d+)\sfrom\sBin-\d+-\d+\sto\sLocation:(?&amp;lt;station_number&amp;gt;\d+)"
| where isnotnull(station_number)
| eventstats count(item) as item_count latest(_time) as last_item_time by station_number
| eval last_item_time=strftime(last_item_time, "%Y-%m-%d %H:%M:%S")
| table station_number, item_count, last_item_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I don't believe you should be using eventstats - you are only interested in 3 fields, station_number, item_count and last_item_time, so use stats instead. It will make your inner search faster.&lt;/P&gt;&lt;P&gt;Note: Use of join is very dependent on data sizes - if you are joining against an inner data set that is large (typically &amp;gt;50,000) you will get unreliable outputs.&lt;/P&gt;&lt;P&gt;Note2: It is almost always possible to use a single search with a stats command to aggregate results like these.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jun 2021 23:06:53 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2021-06-16T23:06:53Z</dc:date>
    <item>
      <title>How to keep results with a count of 0</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556055#M157889</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a search that is joining two searches (one for cart details and one for items that have been brought to the carts). I am trying to count the number of items that have been moved to each cart, but my query is not keeping result that have an item count of 0.&lt;/P&gt;&lt;P&gt;How can I keep the results with an item count of 0? My search is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=INDEX host=HOSTNAME sourcetype=SOURCETYPE&lt;BR /&gt;| rex field=_raw "Cart:\s(?&amp;lt;cart_id&amp;gt;\d+)\sbegin"&lt;BR /&gt;| rex field=_raw "Cart:\s(?&amp;lt;cart_id&amp;gt;\d+)\sselect\snew\ssection:\s(?&amp;lt;section&amp;gt;\d+)"&lt;BR /&gt;| rex field=_raw "Cart:\s(?&amp;lt;cart_id&amp;gt;\d+)\sset\scurrent\slocation\ssuccess:\s(?&amp;lt;section_name&amp;gt;\w+-\d+)"&lt;BR /&gt;| rex field=_raw "Cart:\s(?&amp;lt;cart_id&amp;gt;\d+)\snext\slocation\sis:(?&amp;lt;section_name&amp;gt;\w+-\d+)"&lt;BR /&gt;| rex field=_raw "Cart:\s(?&amp;lt;cart_id&amp;gt;\d+)\sset\scurrent\slocation\ssuccess:\s\w+-(?&amp;lt;station_number&amp;gt;\d+)"&lt;BR /&gt;| rex field=_raw "Cart:\s(?&amp;lt;cart_id&amp;gt;\d+)\snext\slocation\sis:\w+-(?&amp;lt;station_number&amp;gt;\d+)"&lt;BR /&gt;| eval select_time=if(like(_raw, "%set current location%"), _time, null)&lt;BR /&gt;| eval selected_at=strftime(select_time, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| where cart_id&amp;gt;200 and ((like(_raw, "%next location%") and like(section_name, "AA%")) or (like(_raw, "%set current location%") and like(section_name, "BB%")) or like(_raw, "%begin%") or (like(_raw, "%select new section%")))&lt;BR /&gt;| stats latest(section) as section_id latest(section_name) as section_name latest(station_number) as station_number latest(selected_at) as selected_at by cart_id&lt;BR /&gt;| where isnotnull(section_name) and isnotnull(cart_id)&lt;BR /&gt;| join station_number [search index=INDEX host=HOSTNAME sourcetype=SOURCETYPE&lt;BR /&gt;| rex field=_raw "Move\sItem-(?&amp;lt;item&amp;gt;\w+\-\d+\-\d+\-\d+)\sfrom\sBin-\d+-\d+\sto\sLocation:(?&amp;lt;station_number&amp;gt;\d+)"&lt;BR /&gt;| where isnotnull(station_number)&lt;BR /&gt;| eventstats count(item) as item_count latest(_time) as last_item_time by station_number&lt;BR /&gt;| eval last_item_time=strftime(last_item_time, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| table station_number, item_count, last_item_time]&lt;BR /&gt;| where like(section_name, "%AA%") or like(section_name, "%BB%")&lt;BR /&gt;| table cart_id, section_id, section_name, station_number, selected_at, last_item_time, item_count&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 22:06:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556055#M157889</guid>
      <dc:creator>Traer001</dc:creator>
      <dc:date>2021-06-16T22:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep results with a count of 0</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556061#M157893</link>
      <description>&lt;P&gt;If you want to keep the cart details (outer search) where the inner search (items) does not have any items for the station number, then you should use an outer/left join, i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| join type=left station_number [...]&lt;/LI-CODE&gt;&lt;P&gt;and then you need to do what you want to do with last_item_time and item_count to either leave those as null or put in some default value, e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fillnull value=0 item_count&lt;/LI-CODE&gt;&lt;P&gt;by the way, your inner search is doing this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;search index=INDEX host=HOSTNAME sourcetype=SOURCETYPE
| rex field=_raw "Move\sItem-(?&amp;lt;item&amp;gt;\w+\-\d+\-\d+\-\d+)\sfrom\sBin-\d+-\d+\sto\sLocation:(?&amp;lt;station_number&amp;gt;\d+)"
| where isnotnull(station_number)
| eventstats count(item) as item_count latest(_time) as last_item_time by station_number
| eval last_item_time=strftime(last_item_time, "%Y-%m-%d %H:%M:%S")
| table station_number, item_count, last_item_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I don't believe you should be using eventstats - you are only interested in 3 fields, station_number, item_count and last_item_time, so use stats instead. It will make your inner search faster.&lt;/P&gt;&lt;P&gt;Note: Use of join is very dependent on data sizes - if you are joining against an inner data set that is large (typically &amp;gt;50,000) you will get unreliable outputs.&lt;/P&gt;&lt;P&gt;Note2: It is almost always possible to use a single search with a stats command to aggregate results like these.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 23:06:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556061#M157893</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-06-16T23:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep results with a count of 0</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556178#M157930</link>
      <description>&lt;P&gt;Thank you! This worked perfectly. I'm also making the changes you recommended. I'm not too familiar with what can optimize these searches, so this was helpful!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 13:57:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-keep-results-with-a-count-of-0/m-p/556178#M157930</guid>
      <dc:creator>Traer001</dc:creator>
      <dc:date>2021-06-17T13:57:34Z</dc:date>
    </item>
  </channel>
</rss>

