Admin Manual

 


About the Splunk Admin Manual
How Splunk Works

Create indexed fields via configuration files

This documentation does not apply to the most recent version of Splunk. Click here for the latest version.

Create indexed fields via configuration files

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.


Configuration

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.

transforms.conf

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

props.conf

Add the following lines to $SPLUNK_HOME/etc/system/local/props.conf:

[<spec>]
TRANSFORMS-<value> = <unique_stanza_name>

fields.conf

Add an entry to fields.conf for your new indexed field.

[<your_custom_field_name>]
INDEXED=true


Examples

Example 1

This example creates an indexed field called err_code.

transforms.conf

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:

props.conf

Add the following lines to $SPLUNK_HOME/etc/system/local/props.conf:

[testlog]
TRANSFORMS-netscreen = netscreen-error

fields.conf

Add the following lines to $SPLUNK_HOME/etc/system/local/fields.conf:

[err_code]
INDEXED=true

Example 2

This example creates two indexed fields called username and login_result.

transforms.conf

[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.

props.conf

[ftpd-log]
TRANSFORMS-login = ftpd-login

fields.conf

[username]
INDEXED=true
[login_result]
INDEXED=true

How indexed fields work in detail

Splunk builds indexed fields by writing to _meta. Here's how it works:

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.

Quoting example

WRITE_META = true

FORMAT = field1::value field2::"value 2" field3::"a field with a \" quotation mark" field4::"a field which ends with a backslash\\"

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 , 3.4.14 View the Article History for its revisions.


You must be logged into splunk.com in order to post comments. Log in now.

Was this documentation topic helpful?

If you'd like to hear back from us, please provide your email address:

We'd love to hear what you think about this topic or the documentation as a whole. Feedback you enter here will be delivered to the documentation team.

Feedback submitted, thanks!