<?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: Using sub search result to add to main search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542152#M153569</link>
    <description>&lt;P&gt;How is the result incorrect?&lt;/P&gt;&lt;P&gt;Have you run each search separately to verify they return the expected results?&amp;nbsp; If they do, then run the full query without the last &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; command.&amp;nbsp; This should shed light on where the query is failing.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Mar 2021 12:56:47 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2021-03-03T12:56:47Z</dc:date>
    <item>
      <title>Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542002#M153511</link>
      <description>&lt;P&gt;Hi, I have a main search that look like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main RESPONSE_CODE="0" earliest =-4mon@mon latest=mon@mon
|stats count AS Total_success BY MERCHANT_CODE&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will produce a table that has each merchant and their sale for 4 months.&lt;/P&gt;&lt;P&gt;The sub-search that I want to incorporate is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=backend earliest_time=@d
| table CODE ACQ_BANK&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This table has the merchant code (which is the same as above MERCHANT_CODE) and their corresponding bank.&amp;nbsp; And because the data need to be update daily, I limit the search to the latest possible.&lt;/P&gt;&lt;P&gt;I want to produce a table that have that have 3 columns, which are MERCHANT_CODE, Total_success, ACQ_BANK.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 16:10:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542002#M153511</guid>
      <dc:creator>phamxuantung</dc:creator>
      <dc:date>2021-03-02T16:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542040#M153530</link>
      <description>&lt;P&gt;Ideally, the backend index would be a lookup table, updated daily, that the first search would use to map MERCHANT_CODE to ACQ_BANK.&lt;/P&gt;&lt;P&gt;Failing that, I'd use &lt;FONT face="courier new,courier"&gt;append&lt;/FONT&gt; rather than a subsearch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main RESPONSE_CODE="0" earliest =-4mon@mon latest=mon@mon
|stats count AS Total_success BY MERCHANT_CODE
| append [search index=backend earliest_time=@d
  | rename CODE as MERCHANT_CODE
  | table MERCHANT_CODE ACQ_BANK
]
| stats values(*) as * by MERCHANT_CODE
| table MERCHANT_CODE, Total_success, ACQ_BANK&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 12:51:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542040#M153530</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-03-03T12:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542092#M153550</link>
      <description>&lt;P&gt;Hello richgalloway,&lt;/P&gt;&lt;P&gt;Thank you for your reply, I applied your code but the ACQ_BANK column is blank, and it even make the result incorrect. To clarify, my complete query is (after adding yours)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index1 RESPONSE_CODE="0"
| stats count AS Total_trans count(eval(date_hour&amp;gt;=20 OR date_hour&amp;lt;=5)) AS Total_trans_night BY MERCHANT_CODE
|eval RATE=round((Total_trans_night/Total_trans)*100,2)
|search RATE&amp;gt;70
|append [search index=backend earliest=-d@d latest=now
|rename CODE AS MERCHANT_CODE
|table MERCHANT_CODE, ACQ_BANK
]
|stats values(*) AS * BY MERCHANT_CODE
|table MERCHANT_CODE, ACQ_BANK, Total_trans_night, RATE&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 08:15:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542092#M153550</guid>
      <dc:creator>phamxuantung</dc:creator>
      <dc:date>2021-03-03T08:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542152#M153569</link>
      <description>&lt;P&gt;How is the result incorrect?&lt;/P&gt;&lt;P&gt;Have you run each search separately to verify they return the expected results?&amp;nbsp; If they do, then run the full query without the last &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; command.&amp;nbsp; This should shed light on where the query is failing.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 12:56:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542152#M153569</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-03-03T12:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542284#M153608</link>
      <description>&lt;P&gt;The search ran fine individually. Without the last (stats) include , the result look normal but with the ACQ-BANK blank. With the (stats) however, the result look really weird, it end up show all the merchants and ACQ_BANK even if they don't pass the RATE&amp;gt;70 I set above, most of them are blank, with a few have result, it look like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MERCHANT_CODE|RATE |Total_trans_night|Total_trans|ACQ_BANK
CEB          |88.89|8                |9          |Bank A
CAB          |     |                 |           |Bank B&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And I know the result is wrong because I compare it with the original search&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 03:48:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542284#M153608</guid>
      <dc:creator>phamxuantung</dc:creator>
      <dc:date>2021-03-04T03:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542310#M153620</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/230393"&gt;@phamxuantung&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Why don't you try using join like below?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index1 RESPONSE_CODE="0" 
| stats count AS Total_trans count(eval(date_hour&amp;gt;=20 OR date_hour&amp;lt;=5)) AS Total_trans_night BY MERCHANT_CODE 
| eval RATE=round((Total_trans_night/Total_trans)*100,2) 
| search RATE&amp;gt;70 
| join MERCHANT_CODE 
    [ search index=backend earliest=-d@d latest=now 
    | dedup CODE
    | rename CODE AS MERCHANT_CODE 
    | table MERCHANT_CODE, ACQ_BANK
        ] 
| stats values(*) AS * BY MERCHANT_CODE 
| table MERCHANT_CODE, ACQ_BANK, Total_trans_night, RATE&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 08:18:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542310#M153620</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2021-03-04T08:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using sub search result to add to main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542347#M153637</link>
      <description>&lt;P&gt;The appended search does not filter by RATE, which it can't since it does not have that field.&amp;nbsp; To fix that, move the RATE&amp;gt;70 test to after the last &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; command.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:27:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-sub-search-result-to-add-to-main-search/m-p/542347#M153637</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-03-04T13:27:16Z</dc:date>
    </item>
  </channel>
</rss>

