<?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: Avoid multiple spath for a better performant query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504706#M140950</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215385"&gt;@dmarling&lt;/a&gt;&amp;nbsp;it will perform the same as it's using spath equal number of times as the original query I posted. but I agree the&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;spath(X,Y)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;syntax is better. Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jun 2020 22:50:42 GMT</pubDate>
    <dc:creator>monika0511</dc:creator>
    <dc:date>2020-06-16T22:50:42Z</dc:date>
    <item>
      <title>Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504681#M140940</link>
      <description>&lt;P&gt;I have a json with the following structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
   "version":"v0.2",
   "prints":{
      "urls":[
         {
            "response_time":256,
            "uri":{
               "bool":false,
               "name":"abc"
            },
            "Time":{
               "total":52,
               "db":11
            }
         },
         {
            "response_time":578,
            "uri":{
               "bool":false,
               "name":"xyz"
            },
            "Time":{
               "total":78,
               "db":13
            }
         }
      ]
   }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've to create a table with columns :&amp;nbsp;_time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;BR /&gt;here is my query that I'm trying to optimize by removing multiple spaths&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;basic search rv=*, av=*, wm=*, an=*, et=*
| spath input=data path=prints.urls{} output=urls
| spath input=urls path=response_time output=response_time
| spath input=urls path=uri.name output=uri_name
| spath input=urls path=Time.db output=db_time
| spath input=urls path=Time.total output=total_time
| table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't help but think there would be a more optimized way to get the table.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 17:18:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504681#M140940</guid>
      <dc:creator>monika0511</dc:creator>
      <dc:date>2020-06-17T17:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504693#M140942</link>
      <description>&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.4/SearchReference/TextFunctions#spath.28X.2CY.29" target="_self"&gt;You can use spath in an eval command&lt;/A&gt; and you can chain all of the fields into a single eval with a comma separating each field.&amp;nbsp; This will make it more performant and it removes the need to do multiple spath commands:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;basic search rv=*, av=*, wm=*, an=*, et=*
| eval response_time=spath(data, "prints.urls{}.response_time"),
uri_name=spath(data, "prints.urls{}.uri.name"),
db_time=spath(data, "prints.urls{}.Time.db"),
total_time=spath(data, "prints.urls{}.Time.total")
| table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;&lt;P&gt;Here's a run anywhere example using your sample data to demonstrate that it will work.&amp;nbsp; Keep in mind it won' t have the rv, av, wm, an, and et fields due to that not being present in the sample example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults
| eval data="{
   \"version\":\"v0.2\",
   \"prints\":{
      \"urls\":[
         {
            \"response_time\":256,
            \"uri\":{
               \"bool\":false,
               \"name\":\"abc\"
            },
            \"Time\":{
               \"total\":52,
               \"db\":11
            }
         },
         {
            \"response_time\":578,
            \"uri\":{
               \"bool\":false,
               \"name\":\"xyz\"
            },
            \"Time\":{
               \"total\":78,
               \"db\":13
            }
         }
      ]
   }
}"
| eval response_time=spath(data, "prints.urls{}.response_time"),
uri_name=spath(data, "prints.urls{}.uri.name"),
db_time=spath(data, "prints.urls{}.Time.db"),
total_time=spath(data, "prints.urls{}.Time.total")
| table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 16 Jun 2020 20:32:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504693#M140942</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2020-06-16T20:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504701#M140947</link>
      <description>&lt;P&gt;basic search rv=*, av=*, wm=*, an=*, et=*&lt;BR /&gt;| spath input=data path=prints.urls{} output=urls&lt;/P&gt;&lt;P&gt;| mvexpand urls&amp;nbsp;&lt;/P&gt;&lt;P&gt;| spath input=urls&lt;/P&gt;&lt;P&gt;| rename&amp;nbsp;uri.name as uri_name,&amp;nbsp;Time.db as time_db,&amp;nbsp;Time.total as total_time&lt;/P&gt;&lt;P&gt;|&amp;nbsp;table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try &lt;STRONG&gt;rename&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 21:34:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504701#M140947</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-06-16T21:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504706#M140950</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215385"&gt;@dmarling&lt;/a&gt;&amp;nbsp;it will perform the same as it's using spath equal number of times as the original query I posted. but I agree the&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;spath(X,Y)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;syntax is better. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 22:50:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504706#M140950</guid>
      <dc:creator>monika0511</dc:creator>
      <dc:date>2020-06-16T22:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504707#M140951</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/184221"&gt;@to4kawa&lt;/a&gt;&amp;nbsp;renaming didn't work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 22:50:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504707#M140951</guid>
      <dc:creator>monika0511</dc:creator>
      <dc:date>2020-06-16T22:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504757#M140967</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{\"version\":\"v0.2\",\"prints\":{\"urls\":[{\"response_time\":256,\"uri\":{\"bool\":false,\"name\":\"abc\"},\"Time\":{\"total\":52,\"db\":11}},{\"response_time\":578,\"uri\":{\"bool\":false,\"name\":\"xyz\"},\"Time\":{\"total\":78,\"db\":13}}]}}" 
| spath prints.urls{} output=urls 
| mvexpand urls 
| spath input=urls 
| rename Time.db as db_time, Time.total as total_time, uri.name as uri_name&lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222568"&gt;@monika0511&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;this query works well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 09:19:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504757#M140967</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-06-17T09:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504780#M140975</link>
      <description>&lt;P&gt;Beware that mvexpand can really chew through memory on your search head if you have a large amount of events that it's being applied to. This can cause it to terminate early if your admins are enforcing memory limits on searches or can cause the PID to get killed by OOM Killer on a nix box.&amp;nbsp; If you are okay with a multivalued list type view in your table for each event it's unnecessary to mvexpand.&amp;nbsp; If you do have a requirement that each row be one url array, then just be careful on the amount of data it is being applied to.&lt;/P&gt;&lt;P&gt;Also even though the same amount of spaths are in my original solution, the performance is still better than invoking the spath search command the same amount of times because it is on a single pipe eval which means it's processed all at once.&amp;nbsp; Having multiple pipes with spath will cause it to stop and start at each pipe which will add an admittedly negligible performance reduction.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 12:07:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504780#M140975</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2020-06-17T12:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504781#M140976</link>
      <description>&lt;P&gt;refer to below response as this was a duplicate of that.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 15:01:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504781#M140976</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2020-06-17T15:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504784#M140977</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222568"&gt;@monika0511&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try this also.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;YOUR_SEARCH | spath prints.urls{} output=urls | stats count latest(_time) as Time by urls | rename urls as _raw,Time as _time | extract | rename Time.db as db_time, Time.total as total_time, uri.name as uri_name | table _time uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample Search:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| makeresults 
| eval _raw="{\"version\":\"v0.2\",\"prints\":{\"urls\":[{\"response_time\":256,\"uri\":{\"bool\":false,\"name\":\"abc\"},\"Time\":{\"total\":52,\"db\":11}},{\"response_time\":578,\"uri\":{\"bool\":false,\"name\":\"xyz\"},\"Time\":{\"total\":78,\"db\":13}}]}}" 
| spath prints.urls{} output=urls | stats count latest(_time) as Time by urls | rename urls as _raw,Time as _time | extract | rename Time.db as db_time, Time.total as total_time, uri.name as uri_name | table _time uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 12:32:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504784#M140977</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-06-17T12:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Avoid multiple spath for a better performant query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504785#M140978</link>
      <description>&lt;P&gt;It appears the board has ate my answer I wrote earlier to prove that multiple eval spaths is faster than using even 1 spath command.&amp;nbsp; I'll try again.&lt;/P&gt;&lt;P&gt;Using your original query with your sample here is your search performance on my local machine's splunk install:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults
| eval data="{
   \"version\":\"v0.2\",
   \"prints\":{
      \"urls\":[
         {
            \"response_time\":256,
            \"uri\":{
               \"bool\":false,
               \"name\":\"abc\"
            },
            \"Time\":{
               \"total\":52,
               \"db\":11
            }
         },
         {
            \"response_time\":578,
            \"uri\":{
               \"bool\":false,
               \"name\":\"xyz\"
            },
            \"Time\":{
               \"total\":78,
               \"db\":13
            }
         }
      ]
   }
}"
| spath input=data path=prints.urls{} output=urls
| spath input=urls path=response_time output=response_time
| spath input=urls path=uri.name output=uri_name
| spath input=urls path=Time.db output=db_time
| spath input=urls path=Time.total output=total_time
| table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This search has completed and has returned &lt;SPAN class="emphatic"&gt;1&lt;/SPAN&gt; results by scanning &lt;SPAN class="emphatic"&gt;0&lt;/SPAN&gt; events in &lt;SPAN class="emphatic"&gt;0.119 &lt;/SPAN&gt;seconds&lt;/P&gt;&lt;P&gt;The query I originally proposed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults
| eval data="{
   \"version\":\"v0.2\",
   \"prints\":{
      \"urls\":[
         {
            \"response_time\":256,
            \"uri\":{
               \"bool\":false,
               \"name\":\"abc\"
            },
            \"Time\":{
               \"total\":52,
               \"db\":11
            }
         },
         {
            \"response_time\":578,
            \"uri\":{
               \"bool\":false,
               \"name\":\"xyz\"
            },
            \"Time\":{
               \"total\":78,
               \"db\":13
            }
         }
      ]
   }
}"
| eval response_time=spath(data, "prints.urls{}.response_time"),
uri_name=spath(data, "prints.urls{}.uri.name"),
db_time=spath(data, "prints.urls{}.Time.db"),
total_time=spath(data, "prints.urls{}.Time.total")
| table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This search has completed and has returned &lt;SPAN class="emphatic"&gt;1&lt;/SPAN&gt; results by scanning &lt;SPAN class="emphatic"&gt;0&lt;/SPAN&gt; events in &lt;SPAN class="emphatic"&gt;0.099 &lt;/SPAN&gt;seconds&lt;/P&gt;&lt;P&gt;The search proposed by &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/184221"&gt;@to4kawa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults 
| eval _raw="{\"version\":\"v0.2\",\"prints\":{\"urls\":[{\"response_time\":256,\"uri\":{\"bool\":false,\"name\":\"abc\"},\"Time\":{\"total\":52,\"db\":11}},{\"response_time\":578,\"uri\":{\"bool\":false,\"name\":\"xyz\"},\"Time\":{\"total\":78,\"db\":13}}]}}" 
| spath prints.urls{} output=urls 
| mvexpand urls 
| spath input=urls 
| rename Time.db as db_time, Time.total as total_time, uri.name as uri_name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This search has completed and has returned &lt;SPAN class="emphatic"&gt;2&lt;/SPAN&gt; results by scanning &lt;SPAN class="emphatic"&gt;0&lt;/SPAN&gt; events in &lt;SPAN class="emphatic"&gt;0.244 &lt;/SPAN&gt;seconds&lt;/P&gt;&lt;P&gt;And if you have a requirement that each url in the url array appears on it's own row in your table here's my modified version with the caveat I posed above about mvexpand being problematic on large data sets:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults
| eval data="{
   \"version\":\"v0.2\",
   \"prints\":{
      \"urls\":[
         {
            \"response_time\":256,
            \"uri\":{
               \"bool\":false,
               \"name\":\"abc\"
            },
            \"Time\":{
               \"total\":52,
               \"db\":11
            }
         },
         {
            \"response_time\":578,
            \"uri\":{
               \"bool\":false,
               \"name\":\"xyz\"
            },
            \"Time\":{
               \"total\":78,
               \"db\":13
            }
         }
      ]
   }
}"
| eval urls=spath(data,"prints.urls{}")
| mvexpand urls 
| eval response_time=spath(urls, "response_time"),
uri_name=spath(urls, "uri.name"),
db_time=spath(urls, "Time.db"),
total_time=spath(urls, "Time.total")
| table _time, rv, av, wm, an, et, uri_name, response_time, db_time, total_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This search has completed and has returned &lt;SPAN class="emphatic"&gt;2&lt;/SPAN&gt; results by scanning &lt;SPAN class="emphatic"&gt;0&lt;/SPAN&gt; events in &lt;SPAN class="emphatic"&gt;0.113 &lt;/SPAN&gt;seconds&lt;/P&gt;&lt;P&gt;Ultimately you can see that using a single pipe eval with the spath command on each field you want will produce a more performant query by about 17% to your original query and at 48% improvement compared to the one by &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/184221"&gt;@to4kawa&lt;/a&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 12:46:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avoid-multiple-spath-for-a-better-performant-query/m-p/504785#M140978</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2020-06-17T12:46:26Z</dc:date>
    </item>
  </channel>
</rss>

