find_pair function in APL to search an array of key-value pairs and find the first pair that matches specified key and value patterns. This function combines pattern matching with pair extraction, making it easy to locate specific pairs in collections of metadata or tags.
You use find_pair when working with arrays of pairs (such as tags, labels, or metadata) where you need to find a specific pair based on pattern matching. This is particularly useful in log analysis, OpenTelemetry traces with custom attributes, and any scenario where data is stored as key-value pair arrays.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk SPL, you typically iterate through multi-value fields using
mvfind or use spath for JSON data. APL’s find_pair provides a specialized function for finding key-value pairs with pattern matching.ANSI SQL users
ANSI SQL users
In ANSI SQL, you typically use
JSON_EXTRACT or array functions with LIKE patterns to search arrays. APL’s find_pair provides a more direct approach for pair-based searches.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
array | dynamic | An array of strings representing key-value pairs to search. |
key_pattern | string | A wildcard pattern to match against pair keys. Use * for wildcard matching. |
value_pattern | string | A wildcard pattern to match against pair values. Use * for wildcard matching. |
separator | string | (Optional) The separator between keys and values in the pairs. Defaults to :. |
Returns
Adynamic object representing the first matched pair, with key, value and separator properties. Returns null if no matching pair is found.
Example
Usefind_pair to extract specific metadata from HTTP logs stored as tag arrays.
Query
| _time | uri | tags | server_tag |
|---|---|---|---|
| 2025-05-26 08:15:30 | /api/user | [‘server:web01’, ‘env:production’, ‘region:us-west’] | {“separator”: ”:”, “value”: “web01”, “key”: “server”} |
| 2025-05-26 08:16:45 | /api/data | [‘server:web01’, ‘env:production’, ‘region:us-west’] | {“separator”: ”:”, “value”: “web01”, “key”: “server”} |
List of related functions
- parse_pair: Use
parse_pairto parse a single pair string into key and value. Usefind_pairto search an array of pairs. - pair: Use
pairto create a pair string from a key and value. Usefind_pairto locate existing pairs in arrays. - array_index_of: Use
array_index_offor exact match searches in arrays. Usefind_pairfor pattern-based pair matching. - extract: Use
extractfor regex-based extraction from single strings. Usefind_pairfor structured pair searching in arrays.