<?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: search with joins and append takes too long in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313319#M93792</link>
    <description>&lt;P&gt;@elliotproebstel, sorry I accidentally deleted the screenshot while trying to make it show &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; &lt;/P&gt;</description>
    <pubDate>Tue, 23 Jan 2018 19:40:28 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2018-01-23T19:40:28Z</dc:date>
    <item>
      <title>search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313312#M93785</link>
      <description>&lt;P&gt;Goal is to determine, from specific vulnerabilities found in scans, the percentage that have been ‘fixed’, meaning they are not found in the latest scans. So first we get the vulns for all time, then check the ones related to the latest scans. So alltime – latest = fixed. And fixed / alltime  * 100 = percentage fixed.&lt;BR /&gt;
The search/query takes way too long. How to speed it up?&lt;BR /&gt;
Here is the approach.&lt;/P&gt;

&lt;P&gt;sourcetype=alpha&lt;BR /&gt;
| eval comment=”the above gets the results of the scans All Time”&lt;BR /&gt;
| eval comment=”cve is multivalue field, so split it up so we can lookup a specific CVE”&lt;BR /&gt;
| makemv delim=";" cve | mvexpand cve |  rename cve AS CVE &lt;BR /&gt;
| eval comment=”now just look at the ones we care about”&lt;BR /&gt;
| join CVE [|inputlookup PriorityCVE.csv]&lt;BR /&gt;
| eval comment=”label these as ‘alltime’”&lt;BR /&gt;
| eval ReportKey="alltime"&lt;BR /&gt;
| eval comment=”now get the scans representing the latest info”&lt;BR /&gt;
| append [search sourcetype=alpha | makemv delim=";" cve | mvexpand cve |  rename cve AS CVE &lt;BR /&gt;
| join CVE [|inputlookup PriorityCVE_test.csv]&lt;BR /&gt;
| eval comment=”last_scan_finished is in terms of date not granularity of _time”&lt;BR /&gt;
| convert timeformat="%F" ctime(_time) AS CurScan&lt;BR /&gt;
| eval comment=”the beta source has events over time with last_scan_finished per asset”&lt;BR /&gt;
| join asset_id, CurScan [search sourcetype=beta | dedup asset_id last_scan_finished&lt;BR /&gt;
| fields asset_id last_scan_finished | sort 0 - last_scan_finished | dedup asset_id&lt;BR /&gt;
| convert timeformat="%Y-%m-%d %H:%M:%S.%Q" mktime(last_scan_finished) AS LastScanTmp&lt;BR /&gt;
| convert timeformat="%F" ctime(LastScanTmp) AS CurScan | fields asset_id CurScan] &lt;BR /&gt;
| eval comment=”label those that match the last_scan_finished date as ‘nowtime’”&lt;BR /&gt;
| eval ReportKey="nowtime”&lt;BR /&gt;
| table asset_id CVE ReportKey&lt;BR /&gt;
| eval comment=“get counts”&lt;BR /&gt;
| stats values(ReportKey) as ReportKey by asset_id CVE&lt;BR /&gt;
| eval comment=”if you only have the alltime label, you have been fixed”&lt;BR /&gt;
| eval status=case(mvcount(ReportKey)=2, "Persistent", ReportKey="alltime", "Fixed", true(), "New")&lt;BR /&gt;
| eval comment=”(since all scans are in alltime, there should be no ‘new’)”&lt;BR /&gt;
| eval comment=”need to get the counts into variables for the equation”&lt;BR /&gt;
| stats count AS stots BY status | fields stots | mvcombine delim="," stots&lt;BR /&gt;
| nomv stots | rex field=stots "(?&amp;lt;tot_fix&amp;gt;.&lt;EM&gt;),(?&amp;lt;tot_persist&amp;gt;.&lt;/EM&gt;)"&lt;/P&gt;

&lt;P&gt;| eval comment=”now do the calculation”&lt;BR /&gt;
| eval progress=(tot_fix / (tot_fix + tot_persist)) * 100&lt;BR /&gt;
| table progress&lt;/P&gt;

&lt;P&gt;I also tried an approach that put the last_scan_finished per asset in a lookup table, avoiding the redundant search, but that did not speed it up much (and would introduce the need to keep updating a lookup table).&lt;/P&gt;

&lt;P&gt;Ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:41:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313312#M93785</guid>
      <dc:creator>claatu</dc:creator>
      <dc:date>2020-09-29T17:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313313#M93786</link>
      <description>&lt;P&gt;I'm not going to attempt to follow a wall of search without knowing what your data looks like or what the job inspector output is, so here are some general pointers after skimming over:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;use the &lt;CODE&gt;comment&lt;/CODE&gt; macro instead of &lt;CODE&gt;eval comment="..."&lt;/CODE&gt;, should see a big drop in &lt;CODE&gt;eval&lt;/CODE&gt; time spent in the job inspector. Read &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.1/Search/Addcommentstosearches"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.1/Search/Addcommentstosearches&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;don't use &lt;CODE&gt;| join field [inputlookup foo.csv]&lt;/CODE&gt;, use &lt;CODE&gt;| lookup foo.csv field&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;don't use &lt;CODE&gt;sourcetype=A | ... | append [search sourcetype=A]&lt;/CODE&gt;, you're just loading the same data twice. Read &lt;A href="https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html"&gt;https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;restrict fields before &lt;CODE&gt;mvexpand&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Sun, 21 Jan 2018 20:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313313#M93786</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2018-01-21T20:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313314#M93787</link>
      <description>&lt;P&gt;or &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename COMMENT as "since COMMENT doesn't exist, this takes almost no time"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Jan 2018 22:02:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313314#M93787</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-01-21T22:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313315#M93788</link>
      <description>&lt;P&gt;The macro takes zero computational effort per event because it's removed before the search is launched.&lt;BR /&gt;
The macro can be placed virtually anywhere, not just between commands.&lt;BR /&gt;
The macro is the documented approach, easing transition between environments or users.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 22:57:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313315#M93788</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2018-01-21T22:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313316#M93789</link>
      <description>&lt;P&gt;I just added the &lt;STRONG&gt;eval comment&lt;/STRONG&gt; thing for this posting, I don't actually have it in the real search. But will keep the macro thing in mind for future posts.&lt;/P&gt;

&lt;P&gt;When I read about "lookup", it said the table name had to be in transforms.conf, which I don't have access to.&lt;/P&gt;

&lt;P&gt;Will take a look at the link about multiple sourcetypes, but I have read plenty of search-compare type articles and still haven't found the magic.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 13:52:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313316#M93789</guid>
      <dc:creator>claatu</dc:creator>
      <dc:date>2018-01-22T13:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313317#M93790</link>
      <description>&lt;P&gt;I'm adding this as an answer because I can't add a screenshot to a comment - but this is in response to your thought that you couldn't configure a lookup without file access to transforms.conf. You actually can achieve the same thing through the UI. Go to &lt;CODE&gt;Settings &amp;gt; Lookups&lt;/CODE&gt;, and that will take you to this menu:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4171i8AD27A076E2AD75D/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Under &lt;CODE&gt;Add New&lt;/CODE&gt;, you'll find the settings page to configure your existing CSV as a full lookup, allowing you to use the &lt;CODE&gt;lookup&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 14:30:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313317#M93790</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-22T14:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313318#M93791</link>
      <description>&lt;P&gt;I believe &lt;STRONG&gt;lookup&lt;/STRONG&gt; does not filter out events, unless you use a &lt;STRONG&gt;where&lt;/STRONG&gt; afterwards. And it is only for the lookup table (not the subsearch), and the table is small, so I think not much gain there.&lt;/P&gt;

&lt;P&gt;I was able to eliminate the append search, which greatly sped the thing up, and that is somewhat related to the 129424 answer linked. I restricted fields before the mvexpand. I also changed the end calculation to account for possible zeroes (lack of a status type).&lt;/P&gt;

&lt;P&gt;Here is the latest (final?) version with some abbreviation.&lt;/P&gt;

&lt;P&gt;sourcetype=alpha | fields _time cve asset_id&lt;BR /&gt;&lt;BR /&gt;
| makemv delim=";" cve | mvexpand cve &lt;BR /&gt;
| rename cve AS CVE | join CVE [|inputlookup PriorityCVE.csv]&lt;BR /&gt;
| convert timeformat="%F" ctime(_time) AS CurScan&lt;BR /&gt;
| dedup asset_id CVE CurScan&lt;BR /&gt;
| join asset_id, CurScan type=outer [search sourcetype=beta|... obtain last_scan_finished date AS CurScan &lt;BR /&gt;
| eval vulnstat="nowtime" | fields asset_id CurScan vulnstat]&lt;BR /&gt;
| eval ReportKey=if(isnull(vulnstat),"alltime","nowtime")&lt;BR /&gt;
| table asset_id CVE CurScan ReportKey&lt;BR /&gt;
| stats values(ReportKey) as ReportKey, values(CVE) AS CVEs by asset_id CVE&lt;BR /&gt;
| eval status=case(mvcount(ReportKey)=2, "Persistent", ReportKey="alltime", "Fixed", true(), "New")&lt;BR /&gt;
| stats count(eval(status="Fixed")) AS tFixed, count(eval(status="New")) AS tNew, count(eval(status="Persistent")) AS tPersist&lt;BR /&gt;
| eval progress=(tFixed / (tFixed + tNew + tPersist)) * 100&lt;BR /&gt;
| table progress&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:47:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313318#M93791</guid>
      <dc:creator>claatu</dc:creator>
      <dc:date>2020-09-29T17:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313319#M93792</link>
      <description>&lt;P&gt;@elliotproebstel, sorry I accidentally deleted the screenshot while trying to make it show &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 19:40:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313319#M93792</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-01-23T19:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313320#M93793</link>
      <description>&lt;P&gt;Here's the screenshot again:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4172iB62EB9B9B13E5E4A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 19:50:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313320#M93793</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-23T19:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313321#M93794</link>
      <description>&lt;P&gt;Thanks for uploading the screenshot again!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 19:54:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313321#M93794</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-01-23T19:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: search with joins and append takes too long</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313322#M93795</link>
      <description>&lt;P&gt;Yeah, &lt;CODE&gt;lookup&lt;/CODE&gt; doesn't filter on its own, but you can filter based on its output fields.&lt;/P&gt;

&lt;P&gt;Additionally, if you extract your &lt;CODE&gt;cve&lt;/CODE&gt; field as multivalue right away, you can automatically apply the lookup and filter based on a lookup output field in the generating search - before even the &lt;CODE&gt;mvexpand&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Alternatively, if your lookup is a strong restriction (only few events match the lookup), you could consider this pattern: &lt;CODE&gt;sourcetype=alpha [inputlookup PriorityCVE.csv | rename CVE as cve]&lt;/CODE&gt;&lt;BR /&gt;
That will only load events that have a matching &lt;CODE&gt;cve&lt;/CODE&gt; value, also requires extracting the &lt;CODE&gt;cve&lt;/CODE&gt; field as multivalue right away.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 21:16:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-with-joins-and-append-takes-too-long/m-p/313322#M93795</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2018-01-25T21:16:57Z</dc:date>
    </item>
  </channel>
</rss>

