<?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 I obtain counts of search results fields within a head command eval-expression? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416041#M119763</link>
    <description>&lt;P&gt;Sorry there was a typo in the first search&lt;/P&gt;

&lt;P&gt;index = myindex="widget_a" &lt;BR /&gt;
| eventstats dc(chunk) as number_of_chunk_values_returned&lt;BR /&gt;
| streamstats count&lt;BR /&gt;
| where count&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 23:30:21 GMT</pubDate>
    <dc:creator>jbjerke_splunk</dc:creator>
    <dc:date>2020-09-29T23:30:21Z</dc:date>
    <item>
      <title>How do I obtain counts of search results fields within a head command eval-expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416038#M119760</link>
      <description>&lt;P&gt;I have an index with events in it that, among others, have the fields shown at the bottom of this post&lt;/P&gt;

&lt;P&gt;When I execute &lt;CODE&gt;index = myindex="widget_a"  | streamstats dc(chunk)&lt;/CODE&gt;, the results include 9 events as expected. The chunk field is in the search results with 3 values (widget_a_chunk_a, widget_a_chunk_b, and widget_a_chunk_c) as expected. My goal is to extend the query such that the search results includes only N events, where N is the number of unique chunk values evaluated at the time the search is run. &lt;/P&gt;

&lt;P&gt;Something like: &lt;CODE&gt;index = myindex="widget_a" | streamstats dc(chunk) | head (number_of_search_results_returned &amp;lt; number_of_chunk_values_returned&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;I've tried &lt;CODE&gt;index = myindex="widget_a"  | streamstats dc(chunk) | head (stats count(_time) &amp;lt; stats count(chunk))&lt;/CODE&gt;, but the search job fails.&lt;/P&gt;

&lt;P&gt;What is the syntax for obtaining counts of search result fields within a head command eval-expression, so I can compare them in the head command eval-expression and thus limit the number of events returned?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time...........................chunk...............widget
2019-02-28T03:10:02.000-0500    widget_a_chunk_c    widget_a
2019-02-28T03:10:01.000-0500    widget_a_chunk_b    widget_a
2019-02-28T03:10:00.000-0500    widget_a_chunk_a    widget_a
2019-02-28T03:05:02.000-0500    widget_a_chunk_c    widget_a
2019-02-28T03:05:01.000-0500    widget_a_chunk_b    widget_a
2019-02-28T03:05:00.000-0500    widget_a_chunk_a    widget_a
2019-02-27T01:15:02.000-0500    widget_a_chunk_c    widget_a
2019-02-27T01:15:01.000-0500    widget_a_chunk_b    widget_a
2019-02-27T01:15:00.000-0500    widget_a_chunk_a    widget_a
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:30:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416038#M119760</guid>
      <dc:creator>williamcharlton</dc:creator>
      <dc:date>2020-09-29T23:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I obtain counts of search results fields within a head command eval-expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416039#M119761</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I think you need to do something like this&lt;/P&gt;

&lt;P&gt;index = myindex="widget_a" &lt;BR /&gt;
| eventstats dc(chunk) as number_of_chunk_values_returned&lt;BR /&gt;
| streamstats count&lt;BR /&gt;
| where count&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:30:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416039#M119761</guid>
      <dc:creator>jbjerke_splunk</dc:creator>
      <dc:date>2020-09-29T23:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I obtain counts of search results fields within a head command eval-expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416040#M119762</link>
      <description>&lt;P&gt;@jbjerke_splunk &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eventstats dc(chunk) as number_of_chunk_values_returned&lt;/CODE&gt; - this part yields 3 as expected&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| streamstats count&lt;/CODE&gt; - this part yields 9 - ???&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| where count&lt;/CODE&gt; - this part causes the search job to fail&lt;/P&gt;

&lt;P&gt;May I ask what your thinking behind your approach is?   I assume you believe I don't need the &lt;CODE&gt;head&lt;/CODE&gt; command?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 17:12:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416040#M119762</guid>
      <dc:creator>williamcharlton</dc:creator>
      <dc:date>2019-03-06T17:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I obtain counts of search results fields within a head command eval-expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416041#M119763</link>
      <description>&lt;P&gt;Sorry there was a typo in the first search&lt;/P&gt;

&lt;P&gt;index = myindex="widget_a" &lt;BR /&gt;
| eventstats dc(chunk) as number_of_chunk_values_returned&lt;BR /&gt;
| streamstats count&lt;BR /&gt;
| where count&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:30:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416041#M119763</guid>
      <dc:creator>jbjerke_splunk</dc:creator>
      <dc:date>2020-09-29T23:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I obtain counts of search results fields within a head command eval-expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416042#M119764</link>
      <description>&lt;P&gt;Ok so, the searches are being stripped from answer. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index = myindex="widget_a" 
| eventstats dc(chunk) as number_of_chunk_values_returned
| streamstats count
| where count&amp;lt;number_of_chunk_values_returned
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The streamstats command creates a rowcount that you can use to filter with the where command. You cannot have dynamic values in the head command so it would not be helpful in this instance.&lt;/P&gt;

&lt;P&gt;j&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 17:57:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416042#M119764</guid>
      <dc:creator>jbjerke_splunk</dc:creator>
      <dc:date>2019-03-06T17:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I obtain counts of search results fields within a head command eval-expression?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416043#M119765</link>
      <description>&lt;P&gt;@williamcharlton0028 &lt;BR /&gt;
Looking at your statement: My goal is to extend the query such that the search results includes only N events where N is the number of unique chunk values evaluated at the time the search is run.&lt;BR /&gt;
For obtaining unique values, dedup didn't worked for you? &lt;BR /&gt;
To my understanding you should try something like this&lt;BR /&gt;
index=myindex widget="widget_a"  | dedup chunk&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 18:36:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-obtain-counts-of-search-results-fields-within-a-head/m-p/416043#M119765</guid>
      <dc:creator>cvssravan</dc:creator>
      <dc:date>2019-03-06T18:36:50Z</dc:date>
    </item>
  </channel>
</rss>

