<?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 - clause to match values with main search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99760#M25734</link>
    <description>&lt;P&gt;Thanks Martin. That's exactly the goal, &lt;BR /&gt;
but if piping the subsearch results this way, how would I pass the &lt;BR /&gt;
day=BusyHourDay AND date_hour=BusyHourDay&lt;BR /&gt;
Considering I've to define 'day' with the | convert function ?&lt;/P&gt;

&lt;P&gt;does something wrong in the following expression pops out ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;MAIN_SEARCH day=BusyHourDay AND date_hour=BusyHourDay [search SUBSEARCH
| rename day AS BusyHourDay, date_hour AS BusyHour
| fields BusyHourDay BusyHour | sort BusyHourDay
] 
| convert timeformat="%y-%m-%d" ctime(_time) as day
| chart avg(CpuUsedPct) as AvgUsedCpuPct over day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;</description>
    <pubDate>Fri, 25 Jan 2013 16:50:00 GMT</pubDate>
    <dc:creator>splunk_zen</dc:creator>
    <dc:date>2013-01-25T16:50:00Z</dc:date>
    <item>
      <title>Subsearch - clause to match values with main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99758#M25732</link>
      <description>&lt;P&gt;I'm having trouble using a condition to match a subsearch results with the main search ones,&lt;/P&gt;

&lt;P&gt;running each one individually, the subsearch returns,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;BusyHourDay     BusyHour
13-01-19    18
13-01-23    13
13-01-24    13
....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;while the main search (excluding the &lt;STRONG&gt;where&lt;/STRONG&gt; clause) returns,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;day     AvgUsedCpuPct
13-01-23    35.846345
13-01-24    48.795962
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I statically force one of the subsearch output lines in the where clause: day="13-01-24" AND date_hour=18&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;MAIN_SEARCH | append
[search SUBSEARCH
| rename day AS BusyHourDay, date_hour AS BusyHour
| fields BusyHourDay BusyHour | sort BusyHourDay
] 
| convert timeformat="%y-%m-%d" ctime(_time) as day
| where day="13-01-24" AND date_hour=18
| chart avg(CpuUsedPct) as AvgUsedCpuPct over day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I do get the expected output,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;day     AvgUsedCpuPct
13-01-24    48.795962
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but I'm failing to get any output if using,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where day=BusyHourDay AND date_hour=BusyHour
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;how should I rewrite it to cross the subsearch output with the main one and get a chart of CPU Usage over each day Busiest Hour?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;&lt;BR /&gt;
Ended up using,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  MAIN_SEARCH [search SUB_SEARCH
| fields date_month, date_mday, date_hour
]
| eval CpuUsedPct=USED_CPU
| timechart avg(CpuUsedPct) as AvgUsedCpuPct
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jan 2013 11:49:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99758#M25732</guid>
      <dc:creator>splunk_zen</dc:creator>
      <dc:date>2013-01-25T11:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - clause to match values with main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99759#M25733</link>
      <description>&lt;P&gt;It looks to me as if you wanted to use the results of the subsearch as a filter for the main search, not to append the results as new events to the main search. Consider this: &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.1/Search/Usesubsearchtocorrelateevents"&gt;http://docs.splunk.com/Documentation/Splunk/5.0.1/Search/Usesubsearchtocorrelateevents&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2013 11:55:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99759#M25733</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-01-25T11:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - clause to match values with main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99760#M25734</link>
      <description>&lt;P&gt;Thanks Martin. That's exactly the goal, &lt;BR /&gt;
but if piping the subsearch results this way, how would I pass the &lt;BR /&gt;
day=BusyHourDay AND date_hour=BusyHourDay&lt;BR /&gt;
Considering I've to define 'day' with the | convert function ?&lt;/P&gt;

&lt;P&gt;does something wrong in the following expression pops out ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;MAIN_SEARCH day=BusyHourDay AND date_hour=BusyHourDay [search SUBSEARCH
| rename day AS BusyHourDay, date_hour AS BusyHour
| fields BusyHourDay BusyHour | sort BusyHourDay
] 
| convert timeformat="%y-%m-%d" ctime(_time) as day
| chart avg(CpuUsedPct) as AvgUsedCpuPct over day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2013 16:50:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99760#M25734</guid>
      <dc:creator>splunk_zen</dc:creator>
      <dc:date>2013-01-25T16:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - clause to match values with main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99761#M25735</link>
      <description>&lt;P&gt;The subsearch returns a filter, so you do not need (and cannot) write the day=foo and date=bar filters. Just make sure the fields match, it's all in the docs.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2013 17:03:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99761#M25735</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-01-25T17:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - clause to match values with main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99762#M25736</link>
      <description>&lt;P&gt;Does that mean the fields returned by the subsearch must exist in the main one?&lt;/P&gt;

&lt;P&gt;I'm getting,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'chart' command: The argument '( ( BusyHour=13 AND BusyHourDay=13-01-23 ) OR ( BusyHour=17 AND BusyHourDay=13-01-25 ) OR .... OR ( BusyHour=19 AND BusyHourDay=13-01-20 ) )' is invalid.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;after modifying it to,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;MAIN_SEARCH | eval CpuUsedPct=USED_CPU
| chart avg(CpuUsedPct) as AvgUsedCpuPct over BusyHourDay by BusyHour
[search SUBSEARCH
| rename day AS BusyHourDay, date_hour AS BusyHour
| fields BusyHourDay BusyHour | sort BusyHourDay
]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jan 2013 19:02:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99762#M25736</guid>
      <dc:creator>splunk_zen</dc:creator>
      <dc:date>2013-01-25T19:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - clause to match values with main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99763#M25737</link>
      <description>&lt;P&gt;How would you filter by the fields if they didn't exist?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2013 20:42:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-clause-to-match-values-with-main-search/m-p/99763#M25737</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-01-25T20:42:16Z</dc:date>
    </item>
  </channel>
</rss>

