On this page
extract command
Pull new fields out of an existing field at search time - a placeholder pattern, or a regex with named groups.
Pulls new fields out of an existing text field when the query runs, using either a placeholder pattern or a regular expression with named groups. The fields exist for this query only.
Extracted fields can be filtered, grouped, sorted and projected by the stages that follow, and a name that matches a stored field replaces it for the rest of the query.
Syntax
ObiQL
| extract [field=<field>] pattern="<pattern>"
| extract [field=<field>] regex="<regex>"Square brackets mark an optional part, and angle brackets a value you supply.
Arguments
| Argument | Required | Description |
|---|---|---|
field=<field> | Optional | The field to read from. Defaults to message. Writing it out, usually field=message, makes the query clearer. |
pattern="<pattern>" | Optional | A placeholder pattern. Each <name> becomes a field and <_> skips text you do not need. The pattern matches from the start of the line, and anything after its end is ignored. Two placeholders cannot sit directly next to each other. |
regex="<regex>" | Optional | A regular expression. Only named groups, written (?<name>...), become fields. A bare quoted string after extract is also read as a regex. |
Usage
- Give exactly one pattern or regex. Chain a second
| extractfor another. - A line that does not match gives empty values. The row is kept.
- extract must come before stats or timechart, because aggregation discards the raw text.
- The pattern or regex must be quoted. Escape a double quote inside it with a backslash.
Examples
1. Parse an access log line
ObiQL
| extract field=message pattern="<ip> - - <_> \"<method> <uri> <_>\" <status>" | stats count() by statusReads the client address, method, path and status code, then counts requests per status.
2. Pick one value out with a regex
ObiQL
| extract field=message regex="status=(?<status>\d{3})"Creates a status field from the three digits after status=.
3. Read from a different field
ObiQL
| extract field=log pattern="<level>: <detail>"For senders whose text is under log rather than message.