extract - Parse strings into objects
The extract
function allows you to transform raw strings into structured data by parsing out embedded values and storing them as objects. It supports various extraction strategies to convert unstructured fields into clean, queryable formats.
Syntax
(e|extract) <expression> into <keypath> using <extraction-type>(<extraction-params>) [datatypes keypath:datatype,keypath:datatype,...]
Extractor functions
Extractor functions define how raw strings are parsed and transformed into structured objects when using the extract
keyword. Each function handles a specific format, such as regular expressions, key-value pairs, delimited lists, or escaped JSON. You specify the extractor using the using
clause, which determines how the string will be interpreted. With the right extractor, you can convert unstructured data into clean, queryable objects for filtering, analysis, and visualization.
1. regexp
Parses data using named capture groups in a regular expression.
Input
Query
Output
2. multi_regexp
Extracts all matches of a pattern into an array.
Input
Query
Output
3. kv
Parses a string of key-value pairs into an object.
Input
Query
Output
4. jsonobject
Unescapes and parses a stringified JSON object.
Input
Query
Output
5. split
Splits a string by a delimiter into an array of primitive values.
Input
Query
Output
Using datatypes
to annotate extracted fields
You can provide explicit type annotations to specific fields using the datatypes
clause. This ensures values are stored with the correct type, enabling numerical comparisons, aggregations, and more.
Input
Query
Output
{
"msg": "query_type=fetch query_id=100 query_results_duration_ms=232",
"query_data": {
"query_type": "fetch",
"query_id": "100",
"query_results_duration_ms": 232
}
}
query_results_duration_ms
is now a number, whilequery_id
remains a string.
Note
You only need to specify the extracted field name in datatypes
, not the full keypath.
Summary
The extract
keyword, combined with extractor functions, provides a flexible and powerful way to transform messy strings into usable structured data. Whether you're parsing JSON blobs, splitting CSV-like fields, or decoding regex patterns, the extractor system helps you build clean logs and metrics pipelines in a declarative, readable way.