- 2 minutes to read

Formula - ContextKey

Use the contextKey Formula function with a regular expression to extract matching Key-names from the Log Event context (Key-Value collection).

✅ Extract multiple context keys matching a pattern ✅ Use regular expressions for flexible key filtering ✅ Simplify context key discovery and analysis

🎯 Design Note: The contextKey() function finds all context key names that match a regular expression pattern.


What does the contextKey formula do?

The contextKey() formula extracts all key names from the context that match a provided regular expression. This is useful for finding dynamically named keys or filtering specific context properties.

graph LR A["Input: Context Keys"] --> B["contextKey(regex)"] B --> C["Result: Matching Keys"]

Examples

Let's get you started with the following example (Get all Keys matching the provided regular expression)

Input Expression Result
Order#123
Order#456
Order#789
City=Karlstad
...
contextKey(regex('Order#.*'))
Order#123
Order#456
Order#789
Text Data Context Unique values

Features

  • Extracts all Key names from the Key-Value collection (Context)
  • Uses regular expressions for flexible pattern matching
  • Returns unique matching key names
  • Ideal for dynamic key discovery and filtering

Important

This plugin loads the entire message into RAM. For best performance, use it only on small messages.


How to use the contextKey formula

To configure the Formula plugin with the contextKey function:

  1. Select Formula as the expression type plugin
  2. Write down the expression to use in the 'Expression' text area with the named Key to extract contextKey(regex('Order#.*'))
  3. The Context Key names are displayed in the Message Context tab
  4. The result is displayed

Extract context keys

Syntax

contextKey(regex('Expression'))

Next step