Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/victorialogs/logsql.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,37 @@ This query is equivalent to the following [`exact` filter](https://docs.victoria
app:="nginx"
```

Multiple conditions inside `{...}` are combined with `and` logic by default - a log entry must match all of them:

```logsql
{app="nginx",env="prod"}
```
Comment on lines +567 to +571
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify that AND conditions inside stream filters are written as comma-separated conditions, not with the and keyword, to avoid ambiguity?

I think we should avoid writing and in inline code and use "AND condition" or comma-separated condition instead. It may be clearer to say both "AND condition" and "OR condition" in plain text.

Btw, I don't know the reason for not supporting the and keyword in stream filters. The error message is also incorrect:

return nil, fmt.Errorf("unexpected token %q in _stream filter after %q; want 'or', 'and', '}' or ','", lex.token, f)


Conditions can also be combined with `or` logic using the `or` keyword - a log entry matches if it satisfies at least one of the conditions:

```logsql
{env="prod" or environment="prod"}
```

`and` and `or` conditions can be mixed. `and` has higher precedence than `or`,
so the following query selects log entries where either (`app="nginx"` and `env="prod"`) or `app="mysql"`:

```logsql
{app="nginx",env="prod" or app="mysql"}
```

The stream filter supports `{label in (v1,...,vN)}` and `{label not_in (v1,...,vN)}` syntax.
It is equivalent to `{label=~"v1|...|vN"}` and `{label!~"v1|...|vN"}` respectively. The `v1`, ..., `vN` are properly escaped inside the regexp.
For example, `{app in ("nginx", "foo.bar")}` is equivalent to `{app=~"nginx|foo\\.bar"}` - note that the `.` char is properly escaped.

The `in` operator can be combined with `and`/`or` for concise multi-value matching.
For example, the following query selects log entries where `app` is `nginx` or `mysql` running in `prod` environment,
or any `app` from the `monitoring` env:

```logsql
{env="prod",app in ("nginx","mysql") or env="monitoring"}
```

It is allowed to add `_stream:` prefix in front of `{...}` filter in order to make clear that the filtering is performed
on the [`_stream` log field](https://docs.victoriametrics.com/victorialogs/keyconcepts/#stream-fields).
The following filter is equivalent to `{app="nginx"}`:
Expand Down