<?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: Subsearch to provide search criteria for outer search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/602022#M209537</link>
    <description>&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="logs" host="test"
| rex "(?&amp;lt;failure&amp;gt;failed to subtract|failed to add)"
| rex "^\[(?&amp;lt;item&amp;gt;[\w.-]+)\].+"   
| eventstats values(failure) as failure by item
| where isnotnull(failure)
| rex "^\[(?&amp;lt;item&amp;gt;[\w.-]+)\]\s(?&amp;lt;message&amp;gt;.+)"
| table _time, item, message&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 16 Jun 2022 07:11:49 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2022-06-16T07:11:49Z</dc:date>
    <item>
      <title>How to write a Subsearch to provide search criteria for outer search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/601982#M209518</link>
      <description>&lt;P&gt;Hello, I am trying to do what i believe would be a correlated subquery. I need to search a file for a value, then re-search that same file for everything related to that value.&lt;/P&gt;
&lt;P&gt;In a log file of all items and the messages produced as they are processed, I need to search for specific failure messages, grab the item that failed and re-search the file for all messages related to that item.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What I currently have:&lt;BR /&gt;source="logs" host="test"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; [&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;search source="logs" host="test" ("failed to subtract" OR "failed to add")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; rex "^[(?&amp;lt;item&amp;gt;[\w.-]+)\].+"&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; dedup item&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; fields + item&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;]&amp;nbsp;&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; rex "^[(?&amp;lt;item&amp;gt;[\w.-]+)\]\s(?&amp;lt;message&amp;gt;.+)"&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; table _time, item, message&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The inner [search] gives results on its own, but when placed as a subsearch, the whole provides no results.&lt;/P&gt;
&lt;P&gt;Any help would be appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 18:24:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/601982#M209518</guid>
      <dc:creator>dmerrick</dc:creator>
      <dc:date>2022-06-16T18:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch to provide search criteria for outer search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/602015#M209531</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/246923"&gt;@dmerrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;only one question:&lt;/P&gt;&lt;P&gt;you have the same search condition both in main and subsearch with the only difference of the strings condition in the subsearch, in other words: subsearch is a subset of the main search,&amp;nbsp;&lt;/P&gt;&lt;P&gt;so why don't you use only the subsearch as main?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="logs" host="test" ("failed to subtract" OR "failed to add")
|  rex "^[(?&amp;lt;item&amp;gt;[\w.-]+)\].+"   
|  rex "^[(?&amp;lt;item&amp;gt;[\w.-]+)\]\s(?&amp;lt;message&amp;gt;.+)"
|  table _time, item, message&lt;/LI-CODE&gt;&lt;P&gt;Then use always the index condition so you'll have faster searches.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 06:39:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/602015#M209531</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-06-16T06:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch to provide search criteria for outer search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/602022#M209537</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source="logs" host="test"
| rex "(?&amp;lt;failure&amp;gt;failed to subtract|failed to add)"
| rex "^\[(?&amp;lt;item&amp;gt;[\w.-]+)\].+"   
| eventstats values(failure) as failure by item
| where isnotnull(failure)
| rex "^\[(?&amp;lt;item&amp;gt;[\w.-]+)\]\s(?&amp;lt;message&amp;gt;.+)"
| table _time, item, message&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 16 Jun 2022 07:11:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-Subsearch-to-provide-search-criteria-for-outer/m-p/602022#M209537</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-06-16T07:11:49Z</dc:date>
    </item>
  </channel>
</rss>

