<?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: many results in subsearch? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43003#M10112</link>
    <description>&lt;P&gt;Hi there!  It appears that you can get your information without needing a subsearch, but you'll need to use some &lt;STRONG&gt;stats&lt;/STRONG&gt; and &lt;STRONG&gt;eval&lt;/STRONG&gt; magic with &lt;STRONG&gt;relative time&lt;/STRONG&gt;.  Basically, you'll perform one search that has all of the data you need, then use stats to average by host and eval your report key at the same time.  Try the following, be sure to substitute "value" with the field name you want to use for the average:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-2month@month latest=-0month@month | fields _time value host | stats avg(eval(if(relative_time(_time,"@mon")=relative_time(now(),"-1mon@mon"),value,NULL))) AS "Laatste maand" avg(eval(if(relative_time(_time,"@mon")=relative_time(now(),"-2mon@mon"),value,NULL))) AS "Voorlaatste maand" by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;STRONG&gt;relative_time&lt;/STRONG&gt; function in the eval statement compares the month in each event to the month it's looking for (either last month or the month before), which is a really handy little feature.  Each eval statment basically says "if the month I'm looking for and the month of the event are equal, add the value to the average calculation for this column."  I also added a &lt;STRONG&gt;fields&lt;/STRONG&gt; section to your search to speed things up.  I hope this helps, or is along the lines of what you're looking for.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Aug 2013 17:37:30 GMT</pubDate>
    <dc:creator>wpreston</dc:creator>
    <dc:date>2013-08-22T17:37:30Z</dc:date>
    <item>
      <title>many results in subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43001#M10110</link>
      <description>&lt;P&gt;Hello, newbie here...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-1month@month latest=-0month@month | stats avg(value) by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I execute this search I get about 350.000 matching events and 40 results which I expect since I have 40 servers.&lt;BR /&gt;
Now I want to compare this result with that from the month before so I constructed a search with a subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-2month@month latest=-1month@month | eval ReportKey="Voorlaatste maand" | append [search index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-1month@month latest=-0month@month | eval ReportKey="Laatste maand" | stats avg(value) by reportkey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However executing this search results in "Subsearch produced 50000 results, truncating to maxout 50000". I understand from documentation I shouldn't fiddle with the settings in limits.conf, so:&lt;/P&gt;

&lt;P&gt;How can I limit the amount of results in my subsearch without losing the information?&lt;/P&gt;

&lt;P&gt;Thanks in advance for your time.&lt;/P&gt;

&lt;P&gt;Bert&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2013 06:40:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43001#M10110</guid>
      <dc:creator>BertKraan</dc:creator>
      <dc:date>2013-08-22T06:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: many results in subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43002#M10111</link>
      <description>&lt;P&gt;How about this? appending 2 stats resuls so you don't have to face the limitation of subsearch.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-2month@month latest=-1month@month | stats avg(value) as avg by host | eval ReportKey="2 month ago" | append [search index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-1month@month latest=@month | stats avg(value) avg by host | eval ReportKey="1 month ago"  ] | xyseries host ReportKey avg
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This search will give you a table, where hosts on Y, ReportKeys on X, and avg(count) on X-Y crossed.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2013 09:15:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43002#M10111</guid>
      <dc:creator>melonman</dc:creator>
      <dc:date>2013-08-22T09:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: many results in subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43003#M10112</link>
      <description>&lt;P&gt;Hi there!  It appears that you can get your information without needing a subsearch, but you'll need to use some &lt;STRONG&gt;stats&lt;/STRONG&gt; and &lt;STRONG&gt;eval&lt;/STRONG&gt; magic with &lt;STRONG&gt;relative time&lt;/STRONG&gt;.  Basically, you'll perform one search that has all of the data you need, then use stats to average by host and eval your report key at the same time.  Try the following, be sure to substitute "value" with the field name you want to use for the average:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prd_stats" sourcetype=appman:linux host=foo* attribute=CPUUtilization earliest=-2month@month latest=-0month@month | fields _time value host | stats avg(eval(if(relative_time(_time,"@mon")=relative_time(now(),"-1mon@mon"),value,NULL))) AS "Laatste maand" avg(eval(if(relative_time(_time,"@mon")=relative_time(now(),"-2mon@mon"),value,NULL))) AS "Voorlaatste maand" by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;STRONG&gt;relative_time&lt;/STRONG&gt; function in the eval statement compares the month in each event to the month it's looking for (either last month or the month before), which is a really handy little feature.  Each eval statment basically says "if the month I'm looking for and the month of the event are equal, add the value to the average calculation for this column."  I also added a &lt;STRONG&gt;fields&lt;/STRONG&gt; section to your search to speed things up.  I hope this helps, or is along the lines of what you're looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2013 17:37:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43003#M10112</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2013-08-22T17:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: many results in subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43004#M10113</link>
      <description>&lt;P&gt;This answers my question totally! Thanks, now I'll try to understand the magic of stats, eval and relative time.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2013 06:11:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/many-results-in-subsearch/m-p/43004#M10113</guid>
      <dc:creator>BertKraan</dc:creator>
      <dc:date>2013-08-26T06:11:58Z</dc:date>
    </item>
  </channel>
</rss>

