---
title: Search syntax
description: The ZevSight query language for log search, live tail and log alert rules, with fields, levels, phrases, attributes, OR lists and negation.
url: https://docs.zevsight.com/explore/search-syntax
---

# Search syntax

> The ZevSight query language for log search, live tail and log alert rules, with fields, levels, phrases, attributes, OR lists and negation.

The same query language is used in the explorer's query bar, the `q` parameter of the [Query API](/api/reference/query), [live tail](/explore/live-tail) filters and [log alert rules](/respond/alerts#log-rules). A query is at most 2,000 characters.

```text
service:api env:production level:>=warn "connection reset" attrs.route:/v1/* -attrs.user_id:42
```

## How terms combine

- A query is a list of **terms** separated by spaces. **Every term must match**: terms are ANDed.
- There are no `AND`, `OR` or `NOT` keywords, no parentheses and no regular expressions.
- For OR, put several values in **one field term**, separated by commas: `service:auth,api`.
- A leading `-` negates any term: `-debug`, `-service:auth,api` (neither), `-"connection reset"`.

## Free text

Bare words and quoted phrases match the **log message** only.

| Query | Matches |
|---|---|
| `timeout` | Messages containing the whole word `timeout`. `time` does not match `timeout`. |
| `"connection reset"` | Messages containing that exact phrase, in that order. |
| `payment failed` | Messages containing both words, anywhere. |
| `-healthcheck` | Messages without the word `healthcheck`. |

- Words are matched as whole tokens, case-insensitively (ASCII letters).
- A phrase with several words or punctuation must also appear as an exact substring, ignoring case. `"reset connection"` does not match `Connection RESET`.
- `*` in free text is a literal character, not a wildcard.
- Text made only of punctuation, such as `"..."`, is an error.

## Fields

| Field | Example | Notes |
|---|---|---|
| `service:` | `service:checkout` | Case-insensitive. |
| `env:` or `environment:` | `env:production,staging` | Case-insensitive. |
| `level:` or `severity:` | `level:error`, `level:>=warn` | See [Levels](#levels). |
| `trace:` | `trace:4bf92f3577b34da6a3ce929d0e0e4736` | Exact trace id, case-insensitive. |
| `type:` | `type:log`, `type:heartbeat,check_result` | `log`, `heartbeat`, `check_result`. Case-sensitive. |
| `attrs.<key>:` | `attrs.route:/v1/pay` | Exact, **case-sensitive**. `*` is a wildcard. |
| `resource.<key>:` | `resource.host.name:web-1` | Exact, case-sensitive. `*` is a wildcard. |

- An empty value (`service:`) is an error.
- An unknown field name, such as `host:web-1`, is treated as free text.
- Attribute keys are flat. `attrs.user.id` looks up the key `user.id`, as sent by loggers that flatten nested objects.
- A missing attribute reads as an empty value. So `attrs.x:*` matches every event, and there is no "field exists" test.

> **Warning: Values cannot contain spaces**
>
> A field value ends at the first space, and quoted field values such as `attrs.who:"Ada Obi"` are refused. Match part of the value with a wildcard (`attrs.who:Ada*`) or search the message text instead.

### Lists and wildcards

- `level:error,fatal`, `type:log,heartbeat`, `attrs.route:/v1/pay,/v1/cart`: any of the values.
- A value with `*` is a wildcard and can be mixed into a list: `attrs.route:/v1/*,/v2/pay`.
- At most 50 values per term. Empty values (`service:a,,b`) are an error.
- `\,` is a literal comma and `\\` a literal backslash.

## Levels

Levels in order: `trace` < `debug` < `info` < `warn` < `error` < `fatal`.

| Query | Matches |
|---|---|
| `level:error` | Exactly `error` |
| `level:error,fatal` | `error` or `fatal` |
| `level:>=warn` | `warn`, `error`, `fatal` |
| `level:<info` | `trace`, `debug`, and events with no level |

- Comparisons are `>=`, `<=`, `>` and `<`, and work only on `level`. They cannot be combined with a list: `level:>=warn,error` is an error.
- Common logger spellings are accepted: `warning`, `err`, `crit`, `critical`, `panic`, `notice`, `verbose`, `dbg` and others.
- Events with no level (heartbeat pings, check results) count as below `trace`, so `level:<=info` includes them.

## Examples

```text
service:api env:production level:>=error
"payment provider timeout" -env:development
service:checkout attrs.route:/v1/pay level:>=warn
trace:4bf92f3577b34da6a3ce929d0e0e4736
type:heartbeat attrs.monitor:nightly-export
resource.host.name:web-1 -level:debug
attrs.status:5*
service:auth,api -"health check"
```

## Errors

An invalid query returns `400 INVALID_REQUEST` with a message saying what is wrong, for example `attrs.who: needs a value`. Common causes: an unclosed quote, an unknown level (`level:loud`), an empty value, an unknown `type`, or a list with a level comparison.
