Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Ftextsearch.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Ftextsearch.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `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`), `=`, `/`, `:`, `@`, `#`, `$`, `*`, `|`, `,`, `;`, `'`, `"`, `(`, `[`, `{`, `}`, `)`, `]`, `&lt;`, `&gt;`, `.`, `_`, `-`.

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](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

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

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

## 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",

    }

}
```

### Example query

* Function notation
* Method notation

```
textSearch(doc, 'mi')
```

```
doc.textSearch('mi')
```

### Example output

```
{

    true,

    true,

    false

}
```
