This documentation does not apply to the most recent version of Splunk.
This documentation applies to the following versions of Splunk: 3.3 , 3.3.1 , 3.3.2 , 3.3.3 , 3.3.4 , 3.4 , 3.4.1 , 3.4.2 , 3.4.3 , 3.4.5 , 3.4.6 , 3.4.8 , 3.4.9 , 3.4.10 , 3.4.11 , 3.4.12 , 3.4.13
Splunk automatically adds indexed fields such as host, source, source type, event type, etc. Create your own custom indexed fields. Once you have created a new indexed field, it appears in the Fields drop-down menu in Splunk Web. You can also search on it, as well, by typing $CUSTOM_FIELD=foo in your search.
Note: Indexed fields have performance implications. Read about how fields work for more information. It is rarely necessary to create indexed fields (versus extracted fields). You may want to use indexed fields if you search for expressions like foo!="bar" or NOT foo="bar" and the field foo nearly always takes on the value bar. Another common reason to use indexed fields is if the value of the field exists outside of the field more often than not. For example, if you commonly search for foo="1", but 1 occurs in many events that do not have foo="1", you may want to index foo.
Define additional indexed fields by editing props.conf, transforms.conf and fields.conf.
Edit these files in $SPLUNK_HOME/etc/system/local/, or your own custom application directory in $SPLUNK_HOME/etc/apps/. For more information on configuration files in general, see how configuration files work.
Add the following lines to $SPLUNK_HOME/etc/system/local/transforms.conf:
[<unique_stanza_name>] REGEX = <your_regex> FORMAT = <your_custom_field_name>::"$1" WRITE_META = true
$UNIQUE_STANZA_NAME = name your stanza. Use this name later to configure props.conf.
REGEX = create a regex that recognizes your custom field value.
FORMAT = inserts <your_custom_field_name> before the value you've extracted via regex as $1.
FORMAT key.
FORMAT = <your_custom_field_name>::"$1"
FORMAT = <your_first_field>::"$1" <your_second_field>::"$2"
WRITE_META = set this to true to write your field name and value to meta. This is where indexed fields are stored.
Add the following lines to $SPLUNK_HOME/etc/system/local/props.conf:
[<spec>] TRANSFORMS-<value> = <unique_stanza_name>
<spec> can be:
<unique_stanza_name> is the name of your stanza from transforms.conf.
<value> is any value you want to give to your stanza to identify its name-space.
Add an entry to fields.conf for your new indexed field.
[<your_custom_field_name>] INDEXED=true
<your_custom_field_name> is the name of the custom field you set in transforms.conf.
INDEXED=true to indicate that the field is indexed.
INDEXED=true. In this case, you must also set INDEXED_VALUE=false if events exists that have values of that field which are not indexed. An example of this case would be a regex like: A(\d+)B, where the string A1234B would yield the value 1234 for the field, but the event cannot be found by searching for 1234.
This example creates an indexed field called err_code.
In $SPLUNK_HOME/etc/system/local/transforms.conf add:
[netscreen-error] REGEX = device_id=[^ ]+\s+\[w+\](.*)(? FORMAT = err_code::"$1" WRITE_META = true
This stanza takes 'device_id=' followed with a word within brackets and a text string terminating with a colon. The source type of the events is testlog.
Comments:
FORMAT = line contains the following values:
err_code:: is the name of the field.
REGEX.
WRITE_META = true is an instruction to write the content of FORMAT to the index.
Add the following lines to $SPLUNK_HOME/etc/system/local/props.conf:
[testlog] TRANSFORMS-netscreen = netscreen-error
Add the following lines to $SPLUNK_HOME/etc/system/local/fields.conf:
[err_code] INDEXED=true
This example creates two indexed fields called username and login_result.
[ftpd-login] REGEX = Attempt to login by user: (.*): login (.*)\. FORMAT = username::"$1" login_result::"$2" WRITE_META = true
This stanza finds the literal text Attempt to login by user: , extracts a username, followed by a colon, and then the result, which is followed by a period. A line might look like
2008-10-30 14:15:21 mightyhost awesomeftpd INFO Attempt to login by user: root: login FAILED.
[ftpd-log] TRANSFORMS-login = ftpd-login
[username] INDEXED=true [login_result] INDEXED=true
Splunk builds indexed fields by writing to _meta. Here's how it works:
DEST_KEY = meta or WRITE_META = true.
WRITE_META = true to append _meta.
Note: Indexed fields with regex-extracted values containing quotation marks will generally not work, and backslashes may also have problems. Extracted fields do not have these limitations.
WRITE_META = true
FORMAT = field1::value field2::"value 2" field3::"a field with a \" quotation mark" field4::"a field which ends with a backslash\\"