<?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: Is it possible to use appendcols without multiple searches to improve efficiency? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182138#M52517</link>
    <description>&lt;P&gt;Thank you for this - my query is now a lot neater and faster.&lt;/P&gt;

&lt;P&gt;The purpose of the dedup was to remove duplicate entries for the same dir/corner/path/name (dcpn) set. It should have been with every search, but I don't think I had duplicate (dcpn) data entries yet. Using a single query as you've described, I should be able to use the dedup at the start to cover the entire query.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Aug 2014 18:03:29 GMT</pubDate>
    <dc:creator>asherman</dc:creator>
    <dc:date>2014-08-14T18:03:29Z</dc:date>
    <item>
      <title>Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182134#M52513</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to build a table of results, and my query has the form:&lt;/P&gt;

&lt;P&gt;search X&lt;BR /&gt;
|dedup block&lt;BR /&gt;
|stats count by block&lt;BR /&gt;
|appendcols [search X | stats ... | eval ... | chart ...]&lt;BR /&gt;
|appendcols [search X | stats ... | eval ... | chart ...]&lt;BR /&gt;
|appendcols [search X | stats ... | eval ... | chart ...]&lt;/P&gt;

&lt;P&gt;Each search is the same while the subsequent operations differ. I can get the table I want, but as my data grows my query's time is increasing a lot. Is it possible for me to save the search (variable based on a given query) so that I can reuse the results and avoid the duplicate searches? Alternatively, is there a better command for this purpose than appendcols?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;Edit:&lt;BR /&gt;
The full query is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test_index3 base="*" corner=*100c*
| dedup dir corner path name
| stats count as paths by block
| appendcols [search index=test_index3 base="*" corner=*100c* 
    | stats count(eval(isNum(base))) as num_vals, count as num_paths by block
    | eval percent=round(num_vals*100/num_paths,2)
    | chart max(percent) as "num_vals" by block]
| appendcols [search index=test_index3 base="*" NOT base="*nan*" corner=*100c* 
    | stats count(eval((base-min)&amp;gt;0 AND (base-max)&amp;lt;0)) AS bounded, count AS num_vals by block
    | eval percent=round(bounded*100/num_vals,2)
    | chart max(percent) as "bounded paths" by block]
| appendcols [search index=test_index3 base="*" NOT base="*nan*" corner=*100c* 
| stats count(eval((base-max)&amp;lt;0)) AS bounded, count AS num_vals by block
    | eval percent=round(bounded*100/num_vals,2)
    | chart max(percent) as "max bounded paths" by block]
| appendcols [search index=test_index3 base="*" NOT base="*nan*" corner=*100c* 
    | stats count(eval((base-min)&amp;gt;0)) AS bounded, count AS num_vals by block
    | eval percent=round(bounded*100/num_vals,2)
    | chart max(percent) as "min bounded paths" by block]
| fields block, paths, num_vals, "bounded paths", "max bounded paths", "min bounded paths" 
| rename num_vals AS "% data"
| rename "bounded paths" AS "% of data bounded"
| rename "max bounded paths" AS "% of data bounded by max"
| rename "min bounded paths" AS "% of data bounded by min"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Aug 2014 14:55:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182134#M52513</guid>
      <dc:creator>asherman</dc:creator>
      <dc:date>2014-08-14T14:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182135#M52514</link>
      <description>&lt;P&gt;Chances are you can do away with the subsearches &lt;EM&gt;and appendcols&lt;/EM&gt; entirely. Post the full search and we'll see.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 15:56:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182135#M52514</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-14T15:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182136#M52515</link>
      <description>&lt;P&gt;Sure, done.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 16:06:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182136#M52515</guid>
      <dc:creator>asherman</dc:creator>
      <dc:date>2014-08-14T16:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182137#M52516</link>
      <description>&lt;P&gt;First off, &lt;CODE&gt;corner=*100c*&lt;/CODE&gt; usually is quite inefficient because of the leading wildcard. If the number of events scanned vs the number of events matched is high then you may be able to speed everything up here. How depends on your data, look for a way to identify relevant events based on full tokens or at least prefixes of tokens, ie without leading wildcards.&lt;/P&gt;

&lt;P&gt;Looking at the search itself, here's how I'd start by combining the first two parts.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(1) index=test_index3 base="*" corner=*100c* | dedup dir corner path name | stats count as paths by block
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;dedup&lt;/CODE&gt; isn't present in the other searches, so let's avoid using it. This basically counts how many distinct quads of &lt;CODE&gt;(dir, corner, path, name)&lt;/CODE&gt; you have for each value of &lt;CODE&gt;block&lt;/CODE&gt;... so you can replace (1) with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(2) index=test_index3 base="*" corner=*100c* | eval dcpn = dir ."###". corner ."###". path ."###". name | stats dc(dcpn) as paths by block
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now let's look at the first subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(3) index=test_index3 base="*" corner=*100c* | stats count(eval(isNum(base))) as num_vals, count as num_paths by block | eval percent=round(num_vals*100/num_paths,2) | chart max(percent) as "num_vals" by block
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That final chart looks useless to me. There only is one row for each block, so that basically does the same as &lt;CODE&gt;fields - num_paths | rename percent as num_vals&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(4) index=test_index3 base="*" corner=*100c* | stats count(eval(isNum(base))) as num_vals, count as num_paths by block | eval num_vals=round(num_vals*100/num_paths,2) | fields - num_paths
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you compare (2) and (4), the searches basically do the same thing. Load the same events and compute some statistics... so you can combine them like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(5) index=test_index3 base="*" corner=*100c* | eval dcpn = dir ."###". corner ."###". path ."###". name
| stats dc(dcpn) as paths, count(eval(isNum(base))) as num_vals, count as num_paths by block 
| eval num_vals=round(num_vals*100/num_paths,2) | fields - num_paths
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without knowing your data - in (1) you dedup before counting the number of paths, in (4) you don't. Is that on purpose? From here it feels weird, but might match your data and use case so I left it as is.&lt;/P&gt;

&lt;P&gt;Using this strategy you should be able to combine the other subsearches into the main search as well.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 16:50:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182137#M52516</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-14T16:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182138#M52517</link>
      <description>&lt;P&gt;Thank you for this - my query is now a lot neater and faster.&lt;/P&gt;

&lt;P&gt;The purpose of the dedup was to remove duplicate entries for the same dir/corner/path/name (dcpn) set. It should have been with every search, but I don't think I had duplicate (dcpn) data entries yet. Using a single query as you've described, I should be able to use the dedup at the start to cover the entire query.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 18:03:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182138#M52517</guid>
      <dc:creator>asherman</dc:creator>
      <dc:date>2014-08-14T18:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182139#M52518</link>
      <description>&lt;P&gt;Ah, I see - then it does indeed makes sense to use &lt;CODE&gt;dedup&lt;/CODE&gt; for the entire search.&lt;/P&gt;

&lt;P&gt;Consider posting the finished search for others who may later find this question.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 18:18:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182139#M52518</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-14T18:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182140#M52519</link>
      <description>&lt;P&gt;Final result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test_index3 base="*" corner=100c*
| dedup dir corner path name hs_or_lp
| eval dcpn = dir ."###". corner ."###". path ."###". name
| stats dc(dcpn) as paths, 
     count(eval(isNum(base))) as num_vals, 
     count(eval((base-min)&amp;gt;0 AND (base-max)&amp;lt;0)) AS bounded, 
     count(eval((base-max)&amp;lt;0)) AS bounded_max, 
     count(eval((base-min)&amp;gt;0)) AS bounded_min by block
  | eval percent=round(num_vals*100/paths,2) 
  | eval bounded_perc=round(bounded*100/num_vals,2) 
  | eval bounded_max_perc=round(bounded_max*100/num_vals,2) 
  | eval bounded_min_perc=round(bounded_min*100/num_vals,2)
| fields block, percent, bounded_perc, bounded_min_perc, bounded_max_perc 
| rename percent as "% of data"
| rename bounded_perc as "% of data bounded"
| rename bounded_max_perc as "% of data bounded by max"
| rename bounded_min_perc as "% of data bounded by min"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Aug 2014 21:54:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182140#M52519</guid>
      <dc:creator>asherman</dc:creator>
      <dc:date>2014-08-14T21:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182141#M52520</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;

&lt;P&gt;By the way, what exactly is the ."###". doing? I'm not entirely clear on why that works.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 21:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182141#M52520</guid>
      <dc:creator>asherman</dc:creator>
      <dc:date>2014-08-14T21:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use appendcols without multiple searches to improve efficiency?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182142#M52521</link>
      <description>&lt;P&gt;The dots concatenate strings, and without knowing your data I added a separator to make fairly sure that concatenating the four fields doesn't mess things up. Here's an example of how things would mess up with unlucky data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;d   c   p   n
1   2   3   45
1   2   34  5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Concatenating those two quads and then &lt;CODE&gt;dedup&lt;/CODE&gt;ing or &lt;CODE&gt;dc()&lt;/CODE&gt;ing would treat them as duplicates despite them obviously not being duplicates - both would end up being &lt;CODE&gt;12345&lt;/CODE&gt;. Adding the separator avoids that with almost certainty without knowing the data.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2014 22:01:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-use-appendcols-without-multiple-searches-to/m-p/182142#M52521</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-14T22:01:36Z</dc:date>
    </item>
  </channel>
</rss>

