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
Consider the following documents:
{
"doc": {
"id": 1,
"name": "forest",
"warning": "ni",
"details": {
"level": 3,
"message": "proceed with caution",
}
},
"doc": {
"id": 2,
"type": "castle",
"extra": {"fun_fact": "ni"}
},
"doc": {
"id": 5,
"village": "camelot",
"motto": "it is a silly place",
}
}
Use textSearch
to locate the value "ni"
inside nested arrays and objects: