<?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: Getting a count of the number of fields associated with a sourcetype in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658812#M227537</link>
    <description>&lt;P&gt;I'm ten years late, so I hope it's not urgent&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;BR /&gt;But here's a solution you can run inline:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#base search here

| stats last(*) AS * by sourcetype 
| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" == "sourcetype", sourcetype, 1)] 
| addtotals 
| fields Total sourcetype&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2023 05:55:18 GMT</pubDate>
    <dc:creator>wrighke</dc:creator>
    <dc:date>2023-09-27T05:55:18Z</dc:date>
    <item>
      <title>Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65851#M16328</link>
      <description>&lt;P&gt;I've done a little looking and poking around but haven't seen an answer to this - hopefully I haven't overlooked something obvious. I'm trying to build a query that counts the number of fields associated with a sourcetype (edit: number of fields associated with the result set based on a query that is looking at a particular sourcetype). While not an exact measurement I believe that will help me hone in on sourcetypes that possibly need additional field extraction/definition work (low numbers = spend some time). &lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2013 17:54:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65851#M16328</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2013-06-17T17:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65852#M16329</link>
      <description>&lt;P&gt;There is no easy way, but you could get interesting data with a search like : &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=splunkd | fieldsummary | eval sourcetype="splunkd" | table field sourcetype&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Then for each interesting sourcetype, save the result in a lookup: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=splunkd | fieldsummary | eval sourcetype="splunkd" | table field sourcetype | outputlookup list_fields.csv append=true&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;and finally run a report on the whole lookup: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| inputlookup list_fields.csv  | stats dc(field) by sourcetype&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2013 18:32:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65852#M16329</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2013-06-17T18:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65853#M16330</link>
      <description>&lt;P&gt;Assume that you want to get the details for sourcetype "WinEventLog:Security". You can get this by enumerating all fields for that singular sourcetype with this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="WinEventLog:Security" | stats mode(*) AS * by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will give you a listing of all fields plus a single row with a sample of the data.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/Untitled501.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;use the tranpose command to re-order the results and ignore the sampling of data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transpose | fields - "row 1" | rename column AS "FIELD_NAME"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will provide a single column with all of the fields associated with the sourcetype:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/Untitled502.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;And from there, the rest is up to you... for instance, to count the number of fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count(FIELD_NAME) AS count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;All together, the search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="WinEventLog:Security" | stats mode(*) AS * by sourcetype | transpose | fields - "row 1" | rename column AS "FIELD_NAME" | stats count(FIELD_NAME) AS count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;gc&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2013 18:57:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65853#M16330</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2013-06-17T18:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65854#M16331</link>
      <description>&lt;P&gt;Very nice! I had not considered this!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2013 14:53:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65854#M16331</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-06-18T14:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65855#M16332</link>
      <description>&lt;P&gt;Both answers so far work great, but to do this one sourcetype at a time would take me &lt;EM&gt;forever&lt;/EM&gt;. I solved this by writing a shell script the uses the CLI to do two things:&lt;/P&gt;

&lt;P&gt;1) Enumerate all sourcetypes.&lt;BR /&gt;
2) Count the number of fields for each sourcetype.&lt;/P&gt;

&lt;P&gt;It looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/bin/bash

# Clear fields.txt
&amp;gt; fields.txt

echo "Building sourcetype list."
splunk search "| metadata type=sourcetypes index=* | table sourcetype" -uri &lt;A href="https://hostname:8089" target="test_blank"&gt;https://hostname:8089&lt;/A&gt; -maxout 10000 -earliest_time '-7d'| tail +3 &amp;gt; sourcetypes.txt

echo "Done."

while read st; do
    echo "Counting fields for $st."
    echo -n $st &amp;gt;&amp;gt; fields.txt
    echo -n ": " &amp;gt;&amp;gt; fields.txt

    # The search returns with some weird leading whitespace, so I use sed to
    # get rid of it.
    splunk search "sourcetype=$st | head 250 | fieldsummary | stats count" -uri &lt;A href="https://hostname:8089" target="test_blank"&gt;https://hostname:8089&lt;/A&gt; | tail -1 | sed 's/^[ \t]*//' &amp;gt;&amp;gt; fields.txt
done &amp;lt; sourcetypes.txt
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Jun 2013 17:17:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65855#M16332</guid>
      <dc:creator>cschmidt0121</dc:creator>
      <dc:date>2013-06-21T17:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65856#M16333</link>
      <description>&lt;P&gt;Just be aware that the fields may vary based on the app context. For example, I can have a field that is defined in my Sales app, but which does not exist in the Search app context. So unless your fields are all global, you will probably miss some.&lt;/P&gt;

&lt;P&gt;The CLI operates in the Search app context.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2013 17:38:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65856#M16333</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-06-21T17:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65857#M16334</link>
      <description>&lt;P&gt;That didn't even occur to me! Thanks for the heads up.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2013 17:42:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65857#M16334</guid>
      <dc:creator>cschmidt0121</dc:creator>
      <dc:date>2013-06-21T17:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65858#M16335</link>
      <description>&lt;P&gt;BTW, great solution! I am going to use it into some of my work!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2013 17:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65858#M16335</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-06-21T17:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65859#M16336</link>
      <description>&lt;P&gt;As cschmidt0121 mentioned the other two answers work well but I have to give it to this poster as he is a student worker in our shop &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2013 22:13:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65859#M16336</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2013-06-23T22:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65860#M16337</link>
      <description>&lt;P&gt;With 6x you can use the foreach command (maybe was there in 5 but not documented?). At any rate here is the search I'm about to start using. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;scope limiting search&amp;gt; | dedup 20 sourcetype punct | table * | fields - _raw date_* index linecount punct eventtype time*pos splunk_server  | foreach * [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'."##".sourcetype."##||" ] | stats max(*) as * |  transpose | rename "row 1" as sourcetype column as field | rex field=sourcetype "##(?&amp;lt;sourcetype&amp;gt;[^#]+)" | eval fieldsort = lower(field) | dedup sourcetype field | sort sourcetype fieldsort | table sourcetype field
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Apr 2014 17:10:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/65860#M16337</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2014-04-23T17:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658812#M227537</link>
      <description>&lt;P&gt;I'm ten years late, so I hope it's not urgent&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;BR /&gt;But here's a solution you can run inline:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#base search here

| stats last(*) AS * by sourcetype 
| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" == "sourcetype", sourcetype, 1)] 
| addtotals 
| fields Total sourcetype&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 05:55:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658812#M227537</guid>
      <dc:creator>wrighke</dc:creator>
      <dc:date>2023-09-27T05:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658813#M227538</link>
      <description>&lt;P&gt;That's unlikely to give you a good representation of fields that actually are part of the data associated with a sourcetype, for example if you just run this on index=_audit&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_audit
| stats last(*) AS * by sourcetype 
| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" == "sourcetype", sourcetype, 1), fields=mvappend(fields, "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;") ] 
| addtotals 
| fields Total sourcetype fields&lt;/LI-CODE&gt;&lt;P&gt;you will get a load of fields associated with audittrail - on 3 different search heads, I get from 149 to 323 fields, most of which are just pulled in due to TAs installed on the search heads.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 06:06:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658813#M227538</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-09-27T06:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a count of the number of fields associated with a sourcetype</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658815#M227540</link>
      <description>&lt;P&gt;For my particular use case, I want to compare the difference between the count of fields extracted in windows event logs before versus after I install the Splunk TA for Windows on my search head.&amp;nbsp;&lt;BR /&gt;It fits my use case, but it might not for others if you have inconsistent configurations across your search head peers, for example.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 06:18:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-a-count-of-the-number-of-fields-associated-with-a/m-p/658815#M227540</guid>
      <dc:creator>wrighke</dc:creator>
      <dc:date>2023-09-27T06:18:33Z</dc:date>
    </item>
  </channel>
</rss>

