fields command: Overview, syntax, and usage

The SPL2 fields command specifies which fields to keep or remove from the search results. By default, the internal fields _raw and _time are included in the output.

Use these links to quickly navigate to the main sections in this topic:

How the SPL2 fields command works

Use the SPL2 fields command to which specify which fields to keep or remove from the search results. Consider the following set of results:

You decide to keep only the quarter and highest_seller fields in the results. You add the fields command to the search:

The results appear like this:

Alternatively, you decide to remove the quota and highest_seller fields from the results. You add this fields command to the search:

The results appear like this:

Syntax

The required syntax is in bold.

fields [+|-] <field-list>

Required arguments

field-list

Syntax: <field>, <field>, ...

Description: Comma-delimited list of fields to keep or remove. You can use a wild card character in the field names, but must enclose those field names in single quotation marks. For example ... | fields host, 'server*'

Optional arguments

+ | -

Syntax: + | -

Description: If the plus ( + ) symbol is specified, only the fields in the field-list are kept in the results. If the negative ( - ) symbol is specified, the fields in the field-list are removed from the results. The symbol you specify applies to all of the fields in the field-list.

Default: +

Note: . Internal fields begin with an underscore character, such as _time. To remove all of the internal fields from the output use a second fields command, for example ... | fields host, status | fields - '_*'.

Usage

Internal fields

The leading underscore is reserved for names of internal fields such as _raw and _time. By default, the internal fields _raw and _time are included in the search results. The fields command does not remove these internal fields unless you explicitly specify that the fields should not appear in the output.

For example, to remove all internal fields, you specify:

To exclude a specific field, such as _raw, you specify:

Note: Be cautious removing the _time field. Statistical commands, such as timechart, cannot display date or time information without the _time field.

Differences between SPL and SPL2

List of fields must be comma-delimited

The list of fields must be comma-delimited. Otherwise a parsing error is returned. Because the include operator ( + ) is the default, it is not shown in these examples.

Version Example 1
SPL ... fields userId ip
SPL2 ... fields userId, ip

Command options must be specified first

Command options must be specified before command arguments. The exclude and include operators are command options.

Version Example 1
SPL ... fields - host src
SPL2 ... fields - host, src

Field names with special characters must be in single quotes

Field names that contain anything other than a-z, A-Z, 0-9, or underscore ( _ ), need to be enclosed in single quotation marks.

Version Example 1
SPL ... fields - "_*" host src
SPL2 ... fields - '_*', host, src