Splunk Cloud

Search Reference

Acrobat logo Download manual as PDF

Acrobat logo Download topic as PDF



Extracts the xpath value from field and sets the outfield attribute.


xpath [outfield=<field>] <xpath-string> [field=<field>] [default=<string>]

Required arguments

Syntax: <string>
Description: Specifies the XPath reference.

Optional arguments

Syntax: field=<field>
Description: The field to find and extract the referenced xpath value from.
Default: _raw
Syntax: outfield=<field>
Description: The field to write, or output, the xpath value to.
Default: xpath
Syntax: default=<string>
Description: If the attribute referenced in xpath doesn't exist, this specifies what to write to the outfield. If this isn't defined, there is no default value.


The xpath command is a distributable streaming command. See Command types.

The xpath command supports the syntax described in the Python Standard Library Supported XPath syntax.


1. Extract values from a single element in _raw XML events

You want to extract values from a single element in _raw XML events and write those values to a specific field.

The _raw XML events look like this:

      <bar nickname="spock">
      <bar nickname="scotty">
      <bar nickname="bones">

Extract the nickname values from _raw XML events. Output those values to the name field.

sourcetype="xml" | xpath outfield=name "//bar/@nickname"

2. Extract multiple values from _raw XML events

Extract multiple values from _raw XML events

The _raw XML events look like this:

   <DataSet xmlns="">

   <DataSet xmlns="">

Extract the values from the identity_id element from the _raw XML events:

... | xpath outfield=identity_id "//DataSet/identity_id"

This search returns two results: identity_id=3017669 and identity_id=1037669.

To extract a combination of two elements, sname with a specific value and instrument_id, use this search:

... | xpath outfield=instrument_id "//DataSet[sname='BARC']/instrument_id"

Because you specify sname='BARC', this search returns one result: instrument_id=912383KM1.

3. Testing extractions from XML events

You can use the makeresults command to test xpath extractions.

You must add field=xml to the end of your search. For example:

| makeresults
| eval xml="<DataSet xmlns=\"\">
| xpath outfield=identity_id "//DataSet/identity_id" field=xml

See also

extract, kvform, multikv, rex, spath, xmlkv

Last modified on 22 July, 2020

This documentation applies to the following versions of Splunk Cloud: 7.0.13, 7.2.9, 8.0.2007, 8.1.2008, 7.2.10, 8.0.2006, 8.1.2009, 8.1.2011, 8.1.2012 (latest FedRAMP release), 8.1.2101, 8.1.2103, 8.2.2104

Was this documentation topic helpful?

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

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters