<?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: How do we optimize the search result time with a query using the append command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422186#M121248</link>
    <description>&lt;P&gt;Summary indexing should help with performance.&lt;/P&gt;

&lt;P&gt;Apologies for the lack of output.  Without data, I was not able to test the query.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Dec 2018 13:46:19 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2018-12-05T13:46:19Z</dc:date>
    <item>
      <title>How do we optimize the search result time with a query using the append command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422181#M121243</link>
      <description>&lt;P&gt;I have a query , where i have multiple append commands used to get the output result.&lt;/P&gt;

&lt;P&gt;The query has 1 index and 3 source paths. Initially, I was using inputlookup to get the data, but now we changed the  source path. The problem now is search time is taking too long, around 8 sec, to return results. I need to optimize that.&lt;/P&gt;

&lt;P&gt;Below is the query...i was thinking if we eliminate the append the query, we could get faster results. Please suggest or if there are any alternate ways.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=csvlookups source="F:\\SplunkMonitor\\lookup_table_sip_pbx_usage.csv" OR source="F:\\SplunkMonitor\\lookup_table_dpt_capacity.csv" OR source="F:\\SplunkMonitor\\csvlookups\\lookup_table_sip_pbx_forecasts.csv"
| eval Date=strftime(strptime(Date,"%m/%d/%Y"),"%Y-%m-%d")
| sort Date, CLLI
| rename CLLI as Office
  |search abc
| stats sum(Usage) as Usage by Office, Date
| append
    [ search index=csvlookups 
    | eval Date=strftime(strptime(Date,"%m/%d/%Y"),"%Y-%m-%d")
    | reverse
    | search Office=abc AND Type="Test-new"
    | fields Date NB_RTU
    | fields - _raw _time ]
| sort Date
| fillnull value=abc Office
| filldown Usage
| filldown NB_RTU
| fillnull value=0 Usage
| eval _time = strptime(Date, "%Y-%m-%d")
| eval latest_time = if("now" == "now", now(), relative_time(now(), "now"))
| where ((_time &amp;gt;= relative_time(now(), "-3y@h")) AND (_time &amp;lt;= latest_time))
| fields - latest_time Date
| append
    [ gentimes start=-1
    | eval Date=strftime(mvrange(now(),now()+60*60*24*365*3,"1mon"),"%F")
    | mvexpand Date
    | fields Date
    | append
        [ search index=csvlookups 
        | rename "Expected Date of Addition" as edate
        | eval edate=strftime(strptime(edate,"%m/%d/%Y"),"%Y-%m-%d")
        | rename edate as "Expected Date of Addition"
        | table Contact Customer "Expected Date of Addition" "Number of Channels" Switch
        | reverse
        | search Customer = "Regular Usage" AND Switch = "$Office$"
        | rename "Number of Channels" as val
        | return $val ]
    | reverse
    | filldown search
    | rename search as Usage
    | where Date != ""
    | reverse
    | append
        [ search index=csvlookups 
        | rename "Expected Date of Addition" as edate
        | eval edate=strftime(strptime(edate,"%m/%d/%Y"),"%Y-%m-%d")
        | rename edate as "Expected Date of Addition"
        | table Contact Customer "Expected Date of Addition" "Number of Channels" Switch
        | reverse
        | search Customer != "Regular Usage" AND Switch = "$Office$"
        | rename "Expected Date of Addition" as Date
        | eval _time=strptime(Date, "%Y-%m-%d")
        | rename "Number of Channels" as Forecast
        | stats sum(Forecast) as Forecast by Date]
    | sort Date
    | rename Switch as Office
    | eval Forecast1 = if(isnull(Forecast),Usage,Forecast)
    | fields - Usage Forecast
    | streamstats sum(Forecast1) as Forecast
    | fields - Forecast1
    | eval Date=strptime(Date, "%Y-%m-%d")
    | eval Date=if(Date &amp;lt; now(), now(), Date) ]
| filldown Usage
| filldown Office
| eval Forecast = Forecast + Usage
| eval Usage = if(Forecast &amp;gt;= 0,NULL,Usage)
| eval _time=if(isnull(_time), Date, _time)
| timechart limit=0 span=1w max(Usage) as Usage, max(NB_RTU) as NB_RTU, max(Forecast) as Forecast by Office
| rename "NB_RTU: $Office$" as "RTU's Purchased", "Usage: $Office$" as "Usage", "Forecast: $Office$" as "Forecast"
| filldown "RTU's Purchased"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 06:36:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422181#M121243</guid>
      <dc:creator>vikashperiwal</dc:creator>
      <dc:date>2018-12-04T06:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do we optimize the search result time with a query using the append command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422182#M121244</link>
      <description>&lt;P&gt;If &lt;CODE&gt;inputlookup&lt;/CODE&gt; was working well you should stick with that as you won't get much faster.&lt;/P&gt;

&lt;P&gt;It's hard to give specific advice about your query without knowing more about the data and your end goals.  In general:&lt;/P&gt;

&lt;P&gt;Filter early.  Make your base query (before the first '|') as specific as possible.  Run your &lt;CODE&gt;where&lt;/CODE&gt; and &lt;CODE&gt;search&lt;/CODE&gt; clauses as soon as you can.&lt;/P&gt;

&lt;P&gt;Use &lt;CODE&gt;fields&lt;/CODE&gt; instead of &lt;CODE&gt;table&lt;/CODE&gt;.  It's more efficient.&lt;/P&gt;

&lt;P&gt;Sort only when necessary.  Usually, it's not necessary.&lt;/P&gt;

&lt;P&gt;Fewer &lt;CODE&gt;appends&lt;/CODE&gt; is better.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 12:51:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422182#M121244</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-12-04T12:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do we optimize the search result time with a query using the append command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422183#M121245</link>
      <description>&lt;P&gt;Thank You for quick response.&lt;/P&gt;

&lt;P&gt;I have noted the points u mentioned for optimistation.&lt;/P&gt;

&lt;P&gt;The reason for not using inputlookup is its the requirement to have source path instead of lookup.&lt;/P&gt;

&lt;P&gt;About te query and its Goal:&lt;BR /&gt;
1 . it will search all the three csv mentioned via source path to which would give Usage , Date and Office,&lt;BR /&gt;
2. then 1 append would filter on the "Office and Type" to get NB_RTU field value&lt;BR /&gt;
search Office=abc AND Type="Test-new"&lt;BR /&gt;
     | fields Date NB_RTU&lt;BR /&gt;
     3. next Append which is used for forecasting had 2 sub append in which $val and forecast (sum )is returned with respect to date.&lt;BR /&gt;
And at end we would be displaying 4 fields in dashboard--_time , Forecast, NB_RTU and Usage&lt;/P&gt;

&lt;P&gt;please let me know if i can give more clarification on any part of query&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:15:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422183#M121245</guid>
      <dc:creator>vikashperiwal</dc:creator>
      <dc:date>2020-09-29T22:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do we optimize the search result time with a query using the append command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422184#M121246</link>
      <description>&lt;P&gt;Here's a quick cut at trimming some fat to speed things up.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=csvlookups source="F:\\SplunkMonitor\\lookup_table_sip_pbx_usage.csv" OR source="F:\\SplunkMonitor\\lookup_table_dpt_capacity.csv" OR source="F:\\SplunkMonitor\\csvlookups\\lookup_table_sip_pbx_forecasts.csv" abc
 | eval Date=strftime(strptime(Date,"%m/%d/%Y"),"%Y-%m-%d")
 | rename CLLI as Office
 | stats sum(Usage) as Usage by Office, Date
 | append
     [ search index=csvlookups Office=abc AND Type="Test-new"
     | eval Date=strftime(strptime(Date,"%m/%d/%Y"),"%Y-%m-%d")
     | fields Date NB_RTU
     | fields - _raw _time ]
 | sort Date
 | fillnull value=abc Office
 | filldown Usage
 | filldown NB_RTU
 | fillnull value=0 Usage
 | eval _time = strptime(Date, "%Y-%m-%d")
 | eval latest_time = now()
 | where ((_time &amp;gt;= relative_time(now(), "-3y@h")) AND (_time &amp;lt;= latest_time))
 | fields - latest_time Date
 | append
     [ gentimes start=-1
     | eval Date=strftime(mvrange(now(),now()+60*60*24*365*3,"1mon"),"%F")
     | mvexpand Date
     | fields Date
     | append
         [ search index=csvlookups Customer = "Regular Usage" AND Switch = "$Office$"
         | rename "Number of Channels" as val
         | return $val ]
     | where Date != ""
     | reverse
     | filldown search
     | rename search as Usage
     | reverse
     | append
         [ search index=csvlookups Customer != "Regular Usage" AND Switch = "$Office$"
         | rename "Expected Date of Addition" as edate
         | eval Date=strftime(strptime(edate,"%m/%d/%Y"),"%Y-%m-%d")
         | rename "Number of Channels" as Forecast
         | stats sum(Forecast) as Forecast by Date]
     | sort Date
     | rename Switch as Office
     | eval Forecast1 = if(isnull(Forecast),Usage,Forecast)
     | fields - Usage Forecast
     | streamstats sum(Forecast1) as Forecast
     | fields - Forecast1
     | eval Date=strptime(Date, "%Y-%m-%d")
     | eval Date=if(Date &amp;lt; now(), now(), Date) ]
 | filldown Usage
 | filldown Office
 | eval Forecast = Forecast + Usage
 | eval Usage = if(Forecast &amp;gt;= 0,NULL,Usage)
 | eval _time=if(isnull(_time), Date, _time)
 | timechart limit=0 span=1w max(Usage) as Usage, max(NB_RTU) as NB_RTU, max(Forecast) as Forecast by Office
 | rename "NB_RTU: $Office$" as "RTU's Purchased", "Usage: $Office$" as "Usage", "Forecast: $Office$" as "Forecast"
 | filldown "RTU's Purchased"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 02:21:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422184#M121246</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-12-05T02:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do we optimize the search result time with a query using the append command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422185#M121247</link>
      <description>&lt;P&gt;thank You for that attempt , but with the above query i am not able to get the output... i was planning to use "summary indexing" and i expect this can be fast enough&lt;/P&gt;

&lt;P&gt;Please suggest if this cold be ideal approach&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 08:54:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422185#M121247</guid>
      <dc:creator>vikashperiwal</dc:creator>
      <dc:date>2018-12-05T08:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do we optimize the search result time with a query using the append command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422186#M121248</link>
      <description>&lt;P&gt;Summary indexing should help with performance.&lt;/P&gt;

&lt;P&gt;Apologies for the lack of output.  Without data, I was not able to test the query.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 13:46:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-optimize-the-search-result-time-with-a-query-using-the/m-p/422186#M121248</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-12-05T13:46:19Z</dc:date>
    </item>
  </channel>
</rss>

