This page explains how to use the parse operator function in APL.
parse
operator in APL enables you to extract and structure information from unstructured or semi-structured text data, such as log files or strings. You can use the operator to specify a pattern for parsing the data and define the fields to extract. This is useful when analyzing logs, tracing information from text fields, or extracting key-value pairs from message formats.
You can find the parse
operator helpful when you need to process raw text fields and convert them into a structured format for further analysis. It’s particularly effective when working with data that doesn’t conform to a fixed schema, such as log entries or custom messages.
Splunk SPL users
rex
command is often used to extract fields from raw events or text. In APL, the parse
operator performs a similar function. You define the text pattern to match and extract fields, allowing you to extract structured data from unstructured strings.ANSI SQL users
parse
operator. Typically, you use string functions such as SUBSTRING
or REGEXP
to extract parts of a text field. However, APL’s parse
operator simplifies this process by allowing you to define a text pattern and extract multiple fields in a single statement.kind
: Optional parameter to specify the parsing mode. Its value can be simple
for exact matches, regex
for regular expressions, or relaxed
for relaxed parsing. The default is simple
.Expression
: The string expression to parse.StringConstant
: A string literal or regular expression pattern to match against.FieldName
: The name of the field to assign the extracted value.FieldType
: Optional parameter to specify the data type of the extracted field. The default is string
.*
: Wildcard to match any characters before or after the StringConstant
....
: You can specify additional StringConstant
and FieldName
pairs to extract multiple values.uri
field using the parse
operator.Query_time | req_duration_ms | uri |
---|---|---|
2024-10-18T12:00:00 | 200 | /api/v1/resource?duration=200 |
2024-10-18T12:00:05 | 300 | /api/v1/resource?duration=300 |
req_duration_ms
from the uri
field and projects the time and duration for each HTTP request.content_type
field to extract the datatype
and format
values separated by a /
. The extracted values are projected as separate fields.
Original string
user_agent
field to extract the operating system name (os_name
) and version (os_version
) enclosed within parentheses. The extracted values are projected as separate fields.
Original string
uri
field to extract the endpoint
value that appears after /api/v1/
. The extracted value is projected as a new field.
Original string
id
field into three parts: region
, tenant
, and userId
. The id
field is structured with these parts separated by hyphens (-
). The extracted parts are projected as separate fields.
Original string
log
field into four separate parts (method
, url
, status
, and responseTime
) based on a structured format. The extracted parts are projected as separate fields.
Original string
podName
, namespace
, phase
, startTime
, nodeName
, hostIP
, and podIP
. The parsing pattern is treated as a regular expression, and the extracted values are assigned to the respective fields.
Original string
extend
operator when you want to add calculated fields without parsing text.project
to select and rename fields after parsing text.extract
to retrieve the first substring matching a regular expression from a source string.extract_all
to retrieve all substrings matching a regular expression from a source string.