<?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: Does fields break streamstats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470056#M132273</link>
    <description>&lt;P&gt;I don't have _time so I think it's a different result.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Oct 2019 13:21:07 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2019-10-26T13:21:07Z</dc:date>
    <item>
      <title>Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470053#M132270</link>
      <description>&lt;P&gt;I have a query using &lt;STRONG&gt;streamstats&lt;/STRONG&gt; that is on the intensive side because I'm not dealing with nicely-formatted data.  (Legacy code FTW)&lt;BR /&gt;
To help with performance, I added the &lt;STRONG&gt;fields&lt;/STRONG&gt; command to extract only the fields for the query to function, but I'm not getting the results I expect anymore.&lt;/P&gt;

&lt;P&gt;This query adds the &lt;EM&gt;prev_field_of_interest&lt;/EM&gt; field as expected.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=my_eventtype
| eval foo=upper(foo)
| eval bar=upper(bar)
| eval foobar=foo+" "+bar
| streamstats current=false window=5 global=false last(field_of_interest) as prev_field_of_interest by foobar
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I add the &lt;STRONG&gt;fields&lt;/STRONG&gt; command, though, I no longer get any &lt;EM&gt;prev_field_of_interest&lt;/EM&gt; fields added to my results, suggesting it somehow broke &lt;STRONG&gt;streamstats&lt;/STRONG&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=my_eventtype
| fields source,sourcetype,index,host,foo,bar,field_of_interest
| eval foo=upper(foo)
| eval bar=upper(bar)
| eval foobar=foo+" "+bar
| streamstats current=false window=5 global=false last(field_of_interest) as prev_field_of_interest by foobar
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All I get are the exact fields I asked for (and calculated via eval).  &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;I thought maybe it was Fast vs. Smart mode.  No difference.&lt;/LI&gt;
&lt;LI&gt;I thought maybe it was the BY clause on an evaluated field, so as a test I changed it to one of the extracted fields.  No difference.&lt;/LI&gt;
&lt;LI&gt;I tried with and without &lt;EM&gt;source&lt;/EM&gt;,&lt;EM&gt;sourcetype&lt;/EM&gt;,&lt;EM&gt;index&lt;/EM&gt;, and &lt;EM&gt;host&lt;/EM&gt;, but their presence made no difference.&lt;/LI&gt;
&lt;LI&gt;Just for giggles, I tried adding &lt;EM&gt;prev_field_of_interest&lt;/EM&gt; to the fields command, thinking maybe fields was processing stuff farther on down the pipe as well.  No difference.  &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Am I doing something wrong or does &lt;STRONG&gt;fields&lt;/STRONG&gt; break &lt;STRONG&gt;streamstats&lt;/STRONG&gt;?&lt;BR /&gt;
It doesn't make sense to me since &lt;STRONG&gt;fields&lt;/STRONG&gt; is a distributable streaming command, whereas &lt;STRONG&gt;streamstats&lt;/STRONG&gt; is centralized streaming...&lt;/P&gt;

&lt;P&gt;Splunk version is 7.0.2&lt;/P&gt;

&lt;P&gt;Thanks!&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:45:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470053#M132270</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-09-30T02:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470054#M132271</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults count=100
| eval foo=substr("abcde",random() % 4 , 1)
| eval bar=substr("abcde",random() % 4 , 1)
| eval field_of_interest=substr("abcdefghijklmnopqrstuvwxyz",random() % 26 , 4)
| fields foo,bar,field_of_interest
| fields - _time
| eval foo=upper(foo)
| eval bar=upper(bar)
| eval foobar=foo+" "+bar
| streamstats current=false window=5 global=false last(field_of_interest) as prev_field_of_interest by foobar
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There seems to be no problem using the transform command.&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.0/Search/Writebettersearches"&gt;Search Manual - Write better searches&lt;/A&gt;&lt;BR /&gt;
Perhaps the &lt;CODE&gt;fields&lt;/CODE&gt; command behaves unexpectedly when the streaming command continues.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eventtype=my_eventtype
| eval foo=upper(foo)
| eval bar=upper(bar)
| eval foobar=foo+" "+bar
| streamstats current=false window=5 global=false last(field_of_interest) as prev_field_of_interest by foobar
| fields source, sourcetype, index, host, foo, bar, foobar, prev_field_of_interest
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Are you not satisfied with the speed here?&lt;BR /&gt;
If you have a little more information to talk about query optimization, we can help.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 00:35:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470054#M132271</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-10-26T00:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470055#M132272</link>
      <description>&lt;P&gt;Hi to4kawa, and thanks for replying.&lt;/P&gt;

&lt;P&gt;Both &lt;EM&gt;foo&lt;/EM&gt; and &lt;EM&gt;bar&lt;/EM&gt; are present in the search result, as they both appear in the arguments to the &lt;STRONG&gt;fields&lt;/STRONG&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| fields source,sourcetype,index,host,foo,bar,field_of_interest
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 12:59:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470055#M132272</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2019-10-26T12:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470056#M132273</link>
      <description>&lt;P&gt;I don't have _time so I think it's a different result.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 13:21:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470056#M132273</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-10-26T13:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470057#M132274</link>
      <description>&lt;P&gt;I agree that this is a bug so the right thing to do is to open a support case so that it will be fixed.  You can probably pin it to the &lt;CODE&gt;search optimization&lt;/CODE&gt; code by disabling that feature as described here:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Search/Built-inoptimization#Turn_off_optimization_for_a_specific_search"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Search/Built-inoptimization#Turn_off_optimization_for_a_specific_search&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 22:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470057#M132274</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-26T22:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470058#M132275</link>
      <description>&lt;P&gt;Thanks, woodcock.  I'll give it a try on Monday when I return to the office and reply back with my results.&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 02:07:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470058#M132275</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2019-10-27T02:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470059#M132276</link>
      <description>&lt;P&gt;OK, frustrated..  I went back to the exact query that I thought I was running last week, and streamstats is working fine in conjunction with fields.  I will keep trying to find the query that was giving me unexpected behavior and come back to this thread to confirm.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 22:47:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470059#M132276</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2019-10-28T22:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470060#M132277</link>
      <description>&lt;P&gt;If I add this to the end of my search, the _time column is populated correctly:&lt;BR /&gt;
| table _time,next_acd_cooker_binary,acd_cooker_binary,acd_custfilecombo&lt;/P&gt;

&lt;P&gt;I don't think fields will drop internal fields like _time.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:47:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470060#M132277</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-09-30T02:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470061#M132278</link>
      <description>&lt;P&gt;Thank you for the help, to4kawa and woodcock.&lt;/P&gt;

&lt;P&gt;I revisited &lt;EM&gt;all&lt;/EM&gt; of the queries I had been working with when I got this result, and this does &lt;STRONG&gt;not&lt;/STRONG&gt; appear to be an issue with Splunk at all.&lt;/P&gt;

&lt;P&gt;Instead, it's the dreaded PEBCAK problem.  I realized I was working with too short of a time range, so my search results did not contain more than 1 event &lt;EM&gt;per value of foobar&lt;/EM&gt; (my BY clause).  Obviously streamstats can't figure out a change in field_of_interest without at least another event with the same value of foobar to compare against.  Therefore, I wasn't getting prev_field_of_interest added to any events.&lt;/P&gt;

&lt;P&gt;Another lightbulb moment was that since I'm not computing any statistics (in the truest sense of the word) with streamstats and am just looking for a change in field_of_interest, the window argument has zero bearing on the result and can be dropped.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:47:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470061#M132278</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-09-30T02:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Does fields break streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470062#M132279</link>
      <description>&lt;P&gt;Accepting this answer.  There is no apparent conflict between fields and streamstats after revisiting my queries.  Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 16:15:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-fields-break-streamstats/m-p/470062#M132279</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2019-10-31T16:15:44Z</dc:date>
    </item>
  </channel>
</rss>

