Contains
Checks if a string value contains a substring, or if an array contains an element.
Overview
The contains condition evaluates whether a field's value contains a specified substring (for strings) or element (for arrays). This is useful for partial matching scenarios where you need to find records containing specific text patterns or array elements.
Use Cases
- Log Filtering: Find log entries containing specific error messages or keywords
- Tag Matching: Route records that have certain tags in an array
- Content Classification: Identify records with specific content patterns
- Search-like Routing: Route based on partial text matches
Configuration
| Setting | Type | Required | Description |
|---|---|---|---|
key | string | Yes | The field path to check. Supports dot notation for nested fields. Use * to check all keys. |
value | string | Yes | The substring or element to search for. |
case_insensitive | boolean | No | If true, performs case-insensitive comparison. |
raw | boolean | No | If true, treats the entire field as a raw string and performs substring matching. |
not | boolean | No | If true, inverts the condition (matches if value is NOT contained). |
Examples
Basic Substring Check
Check if a message contains "error":
Code
Matches:
Code
Does not match:
Code
Case-Insensitive Matching
Match regardless of case:
Code
Matches:
Code
Array Element Check
Check if an array contains a specific element:
Code
Matches:
Code
Does not match:
Code
Nested Field Check
Check substring in a nested field:
Code
Matches:
Code
Does not match:
Code
Exclusion Check
Match records that do NOT contain a value:
Code
Matches:
Code
Does not match:
Code
Wildcard Key Check
Check if any field contains a value:
Code
Matches:
Code
Object Value Check
Check if any value in an object matches:
Code
Matches:
Code
Does not match (partial values don't match):
Code
Raw Mode - Substring in Arrays
Use raw mode to find substrings within array elements:
Code
Matches:
Code
Without raw, this would NOT match because no array element exactly equals "error".
Raw Mode - Search in Complex Structures
Search for text anywhere in a complex structure:
Code
Matches:
Code
Common Patterns
Error Log Routing
Route logs containing error indicators:
Code
Domain-Based Routing
Route emails by domain:
Code
Tag-Based Filtering
Route records with specific tags:
Code
Exclude Debug/Test Data
Filter out debug and test records:
Code
Best Practices
-
Use
case_insensitivefor text searches: Log messages and user-generated content often have inconsistent casing. -
Be specific with substrings: Short substrings like "a" or "in" will match many records unintentionally.
-
Combine with other conditions: Use with
key_existsto handle missing fields gracefully. -
Consider
starts_withorends_with: If you need to match at specific positions, use more specific conditions. -
Use
matches_regexfor complex patterns: For patterns more complex than simple substring matching.
Type Handling
Default Behavior (raw: false)
| Type | Behavior |
|---|---|
| Strings | Substring matching |
| Arrays | Exact element matching (checks if any element equals the value) |
| Objects | Exact value matching (checks if any object value equals the value) |
| Numbers/Booleans | Substring matching on string representation |
| Missing fields | Returns false (or true if not is set) |
Raw Mode (raw: true)
When raw is enabled, the entire field value is treated as a raw string and substring matching is performed. This is useful for searching within arrays or objects without requiring exact matches.
| Type | Behavior |
|---|---|
| All types | Substring matching on the raw JSON representation |
Limitations
- Simple substring matching only (no wildcards or patterns)
- Default array/object matching is exact (use
raw: truefor substring within elements) rawmode matches against JSON representation, which includes syntax characters like[,],",,
Troubleshooting
Not matching expected records:
- Check case sensitivity settings
- Verify the exact substring (watch for spaces)
- Ensure the field path is correct
Too many matches:
- Make the search string more specific
- Add additional conditions to narrow results
- Consider using
starts_withorends_withfor positional matching
Array/Object matching not working as expected:
- Default behavior uses exact element/value matching
- Use
raw: trueto search for substrings within array elements or object values - Example:
["error - failed"]won't match"error"by default, but will withraw: true
Raw mode matching unexpected content:
- Raw mode searches the JSON representation, including syntax characters
- Searching for
","would match any array with multiple elements - Be specific with search terms to avoid false positives