<?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: Count Stats by Two Fields in One Search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63762#M15756</link>
    <description>&lt;P&gt;Couldn't you just do "| chart count by query,q" to get the results for both fields?&lt;/P&gt;</description>
    <pubDate>Tue, 08 Mar 2016 19:49:39 GMT</pubDate>
    <dc:creator>cyphr0st</dc:creator>
    <dc:date>2016-03-08T19:49:39Z</dc:date>
    <item>
      <title>Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63749#M15743</link>
      <description>&lt;P&gt;So I'm running a search that looks like this:&lt;/P&gt;

&lt;P&gt;(host="zakta01.inno-360.com" AND mwv-landscaping.inno-360.com AND "GET \/search" AND query=*) OR (host="web01.inno-360.com" AND source="/var/log/apache2/mwv_ssl_access.log" AND "/profile-services/talent")&lt;/P&gt;

&lt;P&gt;From that comes two fields that I'm interested in getting the stats for: 'query' and 'q'. So if I wanted to just get the stats for one of them i would do:&lt;/P&gt;

&lt;P&gt;... | stats count by query&lt;/P&gt;

&lt;P&gt;My question is how would I combine them so I can get the stats for both 'query' and 'q' in one search?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:53:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63749#M15743</guid>
      <dc:creator>henryt1</dc:creator>
      <dc:date>2020-09-28T11:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63750#M15744</link>
      <description>&lt;P&gt;You can do something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count(query), count(q) by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not sure exactly what you are after but this will give you the counts for query and q by host in the same table.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2012 14:17:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63750#M15744</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-05-30T14:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63751#M15745</link>
      <description>&lt;P&gt;So that's just counting the events by host. I needed the stats counted by 'query' and 'q' together. So instead of having to do:&lt;/P&gt;

&lt;P&gt;... | stats count by query&lt;/P&gt;

&lt;P&gt;and also:&lt;/P&gt;

&lt;P&gt;... | stats count by q&lt;/P&gt;

&lt;P&gt;I would just like to be able to do them in the same search. Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2012 15:18:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63751#M15745</guid>
      <dc:creator>henryt1</dc:creator>
      <dc:date>2012-05-30T15:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63752#M15746</link>
      <description>&lt;P&gt;"...| stats count by query, q " will give you the count   based on both fields.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2012 15:32:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63752#M15746</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-05-30T15:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63753#M15747</link>
      <description>&lt;P&gt;Any other ideas?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2012 15:55:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63753#M15747</guid>
      <dc:creator>henryt1</dc:creator>
      <dc:date>2012-06-01T15:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63754#M15748</link>
      <description>&lt;P&gt;For some reason it doesn't seem to be working. When I try that all I get is 'no results found'.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2012 18:28:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63754#M15748</guid>
      <dc:creator>henryt1</dc:creator>
      <dc:date>2012-06-01T18:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63755#M15749</link>
      <description>&lt;P&gt;Are you looking for count of how many of query and q you see in your result set?  ... | stats count by query q  - does not give you anything?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2012 18:31:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63755#M15749</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-06-01T18:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63756#M15750</link>
      <description>&lt;P&gt;Correct, it doesn't give me anything. I'm looking for the count of both together. &lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2012 15:39:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63756#M15750</guid>
      <dc:creator>henryt1</dc:creator>
      <dc:date>2012-06-04T15:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63757#M15751</link>
      <description>&lt;P&gt;Well perhaps you could do like this, IF &lt;CODE&gt;query&lt;/CODE&gt; only exists in one type of log and &lt;CODE&gt;q&lt;/CODE&gt; only exists in the other;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| rename query AS q | stats count by q
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;Well, I managed to do the same/similar thing for &lt;CODE&gt;WinEventLog:Security&lt;/CODE&gt; and &lt;CODE&gt;access_combined&lt;/CODE&gt; logs, effectively renaming the windows &lt;CODE&gt;EventCode&lt;/CODE&gt; to &lt;CODE&gt;http_status&lt;/CODE&gt; (or if it was the other way around). Thus I had 200, 404 and 500 as values of &lt;CODE&gt;EventCode&lt;/CODE&gt;, or if it was 4624 etc as &lt;CODE&gt;http_status&lt;/CODE&gt; codes.&lt;/P&gt;

&lt;P&gt;Have you tried looking into &lt;CODE&gt;FIELD_ALIAS&lt;/CODE&gt; which is more 'permanent' way doing this?&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/4.3.1/Knowledge/Addaliasestofields"&gt;http://docs.splunk.com/Documentation/Splunk/4.3.1/Knowledge/Addaliasestofields&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2012 16:05:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63757#M15751</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-06-04T16:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63758#M15752</link>
      <description>&lt;P&gt;You are correct about the query only existing in one type of log and q in the other. However when I try your suggestion it converts query to q and brings back all of those results, but it doesn't bring back the original q.&lt;/P&gt;

&lt;P&gt;So for instance if query has 26 results and q has 7, when I rename it like you said and do 'stats count by q' it brings back 26 results still instead of 33.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2012 17:21:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63758#M15752</guid>
      <dc:creator>henryt1</dc:creator>
      <dc:date>2012-06-04T17:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63759#M15753</link>
      <description>&lt;P&gt;see update above. /k&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2012 17:53:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63759#M15753</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-06-04T17:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63760#M15754</link>
      <description>&lt;P&gt;Hi I know its 4 years later but found this thread while looking for a solution and thought I show how I made work&lt;/P&gt;

&lt;P&gt;source=&lt;EM&gt;access&lt;/EM&gt; AND (user != "-") | rename user AS User | append [search source=&lt;EM&gt;access&lt;/EM&gt; AND (access_user != "-") | rename access_user AS User] | stats dc(User) by host&lt;/P&gt;

&lt;P&gt;I created one search and renamed the desired field from "user to "User".  Then I did a sub-search within the search to rename the other desired field from access_user to USER.  Then just stats count by new field name and gave me desired output.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:32:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63760#M15754</guid>
      <dc:creator>kbouchard81</dc:creator>
      <dc:date>2020-09-29T08:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63761#M15755</link>
      <description>&lt;P&gt;Another option could be like this (without subsearch)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=access user!="-" | eval User=coalesce(user,access_user) | stats dc(User) by host
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2016 20:08:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63761#M15755</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-25T20:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63762#M15756</link>
      <description>&lt;P&gt;Couldn't you just do "| chart count by query,q" to get the results for both fields?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2016 19:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63762#M15756</guid>
      <dc:creator>cyphr0st</dc:creator>
      <dc:date>2016-03-08T19:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count Stats by Two Fields in One Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63763#M15757</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
use appendcols command &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(host="zakta01.inno-360.com" AND mwv-landscaping.inno-360.com AND "GET \/search" AND query=*) OR (host="web01.inno-360.com" AND source="/var/log/apache2/mwv_ssl_access.log" AND "/profile-services/talent")| stats count as C1 by query|appendcols[search (host="zakta01.inno-360.com" AND mwv-landscaping.inno-360.com AND "GET \/search" AND query=*) OR (host="web01.inno-360.com" AND source="/var/log/apache2/mwv_ssl_access.log" AND "/profile-services/talent")| stats count as C2  by q]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Mar 2016 09:36:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-Stats-by-Two-Fields-in-One-Search/m-p/63763#M15757</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2016-03-09T09:36:20Z</dc:date>
    </item>
  </channel>
</rss>

