<?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: Limit values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69031#M17327</link>
    <description>&lt;P&gt;I updated the answer, let me know if the update helps&lt;/P&gt;</description>
    <pubDate>Wed, 05 Mar 2014 22:19:29 GMT</pubDate>
    <dc:creator>chris</dc:creator>
    <dc:date>2014-03-05T22:19:29Z</dc:date>
    <item>
      <title>Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69025#M17321</link>
      <description>&lt;P&gt;I have a search that pipes this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats count,values(category) by src_user src_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It returns results with a ton of categories per user and IP.  I would like to limit the values(category) to the top 3 per result.&lt;/P&gt;

&lt;P&gt;Does anyone know how to accomplish this?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Dave&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2013 19:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69025#M17321</guid>
      <dc:creator>ccsfdave</dc:creator>
      <dc:date>2013-06-19T19:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69026#M17322</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by src_user,src_ip,category | sort -count | streamstats count as counter by src_user,src_ip  | stats sum(count) as total_count list(eval(if(counter&amp;lt;4,category,null()))) as values  by src_user,src_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by src_user,src_ip,category 
-&amp;gt; you need the count of every category to find out the top 3 

| sort -count 
-&amp;gt; get the most frequent categorys first

| streamstats count as counter by src_user,src_ip
-&amp;gt; add a rank/counter for the categories by frequency

| stats sum(count) as total_count list(eval(if(counter&amp;lt;4,category,null()))) as values  by src_user,src_ip
-&amp;gt;only take the categories into the final result that have a rank that is smaller than 4 ( = top 3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;----- Udpate ----- &lt;/P&gt;

&lt;P&gt;You could use either the ranking based or a percentage based "base search":&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by src_user,src_ip,category | sort -count | streamstats count as counter by src_user,src_ip | where counter &amp;lt;3 

| stats count by src_user,src_ip,category | eventstats sum(count) as total_hits by src_user,src_ip | eval percentage=count/total_hits | where percentage&amp;gt;0.33 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the filter for categories you are interested in. If you know the interesting categories you could append: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search category=xy OR category=yz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or maybe&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search category!=xy AND category!=yz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to include/exclude the categories based on the frequency they occur you could have a seperate search that populates a lookup with the categories you want to include/exclude (this would be a kind of baseline) and then use that to filter your results. But from what you wrote I am guessing that you know the NSFW categories &lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2013 21:15:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69026#M17322</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2013-06-19T21:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69027#M17323</link>
      <description>&lt;P&gt;Can we take this one step further and then limit the category results to only report if not certain values?  For example, my most common results are computer-and-internet-info, business-and-economy, search-engines.  I would like the results to ignore the most common and only return the results with rare values at the top such as the sports category.&lt;/P&gt;

&lt;P&gt;Any ideas?  Thanks!&lt;/P&gt;

&lt;P&gt;Dave&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2014 23:21:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69027#M17323</guid>
      <dc:creator>ccsfdave</dc:creator>
      <dc:date>2014-02-26T23:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69028#M17324</link>
      <description>&lt;P&gt;Have you tried changeing the "| sort -count" to "|sort count"?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2014 07:45:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69028#M17324</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2014-02-27T07:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69029#M17325</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;

&lt;P&gt;I don't want to reverse the sort.  What I am really looking for is aside from people doing their normal jobs, I would like to see if sports or dating sites are being accessed in high page counts.  So I would like to exclude the above categories but still preserve whether they are frequenting NSFW (really not acceptable) sites.&lt;/P&gt;

&lt;P&gt;Perhaps another way to go about this is to create a percent of sport versus overall page views.  However for that to work, I would only want to see when sports was above say 33%.&lt;/P&gt;

&lt;P&gt;Thanks for helping me think this through!&lt;/P&gt;

&lt;P&gt;Dave&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2014 18:30:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69029#M17325</guid>
      <dc:creator>ccsfdave</dc:creator>
      <dc:date>2014-03-05T18:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69030#M17326</link>
      <description>&lt;P&gt;Hi Dave, I do not understand what information the final result should contain yet. You could edit the the if clause of the second stats to exclude/include categories if you know what they are: &lt;BR /&gt;
| stats sum(count) as total_count list(eval(if((counter&amp;lt;4) AND (category!="search-engines" OR category!="business-and-economy"),category,null()))) as values  by src_user,src_ip &lt;BR /&gt;
That way you still get a result per User &amp;amp; IP with the overall total count of page counts.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:03:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69030#M17326</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2020-09-28T16:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69031#M17327</link>
      <description>&lt;P&gt;I updated the answer, let me know if the update helps&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2014 22:19:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69031#M17327</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2014-03-05T22:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Limit values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69032#M17328</link>
      <description>&lt;P&gt;Yeah, it helped Chris!  I just had to wrap my head around how it would work out.  I will convey this to my customer and hopefully, it is what they are looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 00:50:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Limit-values/m-p/69032#M17328</guid>
      <dc:creator>ccsfdave</dc:creator>
      <dc:date>2014-03-13T00:50:25Z</dc:date>
    </item>
  </channel>
</rss>

