Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fcases%2Fcase_find.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%2Fcases%2Fcase_find.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `case_find`

## Description

Returns a value based on whether a string matches one of several specified text patterns.

This function is a shorthand for `case` expressions with [text match](https://docs-docusaurus.kinsta.page/dataprime/user-guide/foundations/understanding-expressions/.md) (`~`) logic and helps shorten queries that would otherwise repeat conditional statements. Use `case_find` when you want pattern matching — the same behavior the [\`find\`](https://docs-docusaurus.kinsta.page/dataprime/language-reference/commands-reference/find_text/.md) command uses for free-text search. For strict substring containment, use [\`case\_contains\`](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/cases/case_contains/.md) instead. If no clause matches and no `_` fallback is present, `case_find` returns `null`.

Note

`case_find` checks clauses top-to-bottom and returns the **first match**, so order matters.

## Syntax

```
case_find {

s: string,

pattern1 -> result1,

pattern2 -> result2,

...

patternN -> resultN,

_        -> default

}
```

## Arguments

| Name      | Type     | Required  | Description                                                |
| --------- | -------- | --------- | ---------------------------------------------------------- |
| `s`       | `string` | **true**  | The string to match against patterns                       |
| `pattern` | `string` | **true**  | A text pattern to match against `s` using the `~` operator |
| `result`  | `any`    | **true**  | The value to return if the pattern matches                 |
| `_`       | `any`    | **false** | Default value if no patterns match                         |

## Example

**Use case: Classify requests by client type**

Suppose you want to enrich access logs with a `client_type` field based on patterns in the request user-agent. Consider these log documents:

### Example data

```
{

  "user_agent": "Mozilla/5.0 (Windows NT 10.0) Chrome/120.0"

},

{

  "user_agent": "Mozilla/5.0 (Macintosh) Safari/605.1"

},

{

  "user_agent": "GitHub-Hookshot/abc123"

}
```

### Example query

```
create client_type from

  case_find {

    $d.user_agent,

    'Chrome'          -> 'Chrome browser',

    'Safari'          -> 'Safari browser',

    'GitHub-Hookshot' -> 'GitHub webhook',

    _                 -> 'Other'

  }
```

### Example output

```
{

  "user_agent": "Mozilla/5.0 (Windows NT 10.0) Chrome/120.0",

  "client_type": "Chrome browser"

},

{

  "user_agent": "Mozilla/5.0 (Macintosh) Safari/605.1",

  "client_type": "Safari browser"

},

{

  "user_agent": "GitHub-Hookshot/abc123",

  "client_type": "GitHub webhook"

}
```
