textSearch
Description
Searches for a text phrase within a target value.
The behavior depends on the type of the target:
- Primitive types (
string,number,bool,interval,timestamp,regexp,enum) are converted to strings before searching. - Objects are searched by their values (keys are ignored).
- Arrays are searched by their elements.
The phrase must appear as one or more complete tokens. Tokens are defined during log parsing and are split on the following characters: whitespace (\s), =, /, :, @, #, $, *, |, ,, ;, ', ", (, [, {, }, ), ], <, >, ., _, -.
Because of this, a search for online will not match onlineboutique (one token), but will match online_boutique (online and boutique are separate tokens). Similarly, Version 17 matches Version 17.4 (Build 21E213) because Version and 17 are two tokens, but Vers would not match because it is not a full token.
Syntax
Like many functions in DataPrime, textSearch supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| target | T | true | Must be one of string, bool, number, interval, timestamp, regexp, or enum. Objects and arrays are also supported. |
| phrase | string | true | The search string. Must be a literal value, not the result of a calculation |
Example
Find a string in a complex object
Use textSearch to locate the value "mi" inside nested arrays and objects:
Example data
{
"doc": {
"id": 1,
"name": "woods",
"warning": "mi",
"details": {
"level": 3,
"message": "proceed cautiously",
}
},
"doc": {
"id": 2,
"type": "fortress",
"extra": {"fun_fact": "mi"}
},
"doc": {
"id": 5,
"village": "stonekeep",
"motto": "it is a curious place",
}
}