# `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://coralogix.com/docs/dataprime/beginners-guide/expressions/#text-search) (`~`) 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://coralogix.com/docs/dataprime/language-reference/commands-reference/find_text/index.md) command uses for free-text search. For strict substring containment, use [`case_contains`](https://coralogix.com/docs/dataprime/language-reference/functions-reference/cases/case_contains/index.md) instead.

Note

Like all case statements, `case_find` returns the **first matching value**. The order of clauses is important.

## Syntax

```dataprime
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

```json
{
  "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

```dataprime
create client_type from
  case_find {
    $d.user_agent,
    'Chrome'          -> 'Chrome browser',
    'Safari'          -> 'Safari browser',
    'GitHub-Hookshot' -> 'GitHub webhook',
    _                 -> 'Other'
  }
```

### Example output

```json
{
  "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"
}
```
