Skip to content

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.

textSearch(target: T, phrase: string): bool
(target: T).textSearch(phrase: string): bool

Arguments

NameTypeRequiredDescription
targetTtrueMust be one of string, bool, number, interval, timestamp, regexp, or enum. Objects and arrays are also supported.
phrasestringtrueThe 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:

textSearch(doc, 'ni')
doc.textSearch('ni')

Output

{
    true,
    true,
    false
}