CQL reference
Sources, fields, operators, stages, aggregates, limits and error messages.
Verified against v1.0.0-rc.1 · sources
Model#
- A query is
search | stage | stage .... - The time range comes from the time picker, never from query text. Time fields cannot be filtered: the error is
'<f>' is a time field: use the time picker. - Every literal is a bound ClickHouse parameter. Query text is never spliced into SQL.
- Tenant isolation is a ClickHouse row policy, not the compiler.
- Only one of
stats,timechart,top,rareis allowed per query.
Sources#
Select a source with source=<name> as the first term of the query. The default is events.
| Source | Reads | Free text |
|---|---|---|
events | log events | yes |
gaps | reconciler runs with missing events | no |
masking | masked-value counts per rule | no |
alerts | alert state changes | no |
audit | UI audit log | no |
Fields per source#
| Source | Fields |
|---|---|
events | ts, ingest_ts, tenant, log_type, src, boot_id, seq, level, service, host, msg, http_status, http_path, duration_ms, user_tok, k8s_ns, auth_result, orig_ts, mask_flags, signature, norm_version; any other name is read from attrs |
gaps | at, win, run_id, tenant, src, boot_id, expected, stored, missing, dups, cause |
masking | win, tenant, log_type, rule, n |
alerts | at, rule_id, state, value |
audit | seq, at, user_id, action, target, result |
An unknown field on a source other than events is an error that lists the valid fields.
Search expression#
| Form | Meaning |
|---|---|
word | Message contains the word, case-insensitive |
"a phrase" | Message contains the phrase, case-insensitive |
c"Phrase" | Message contains the phrase, case-sensitive |
field=value, field!=value | Equal, not equal |
field>n, >=, <, <= | Numeric comparison. On a text field it is an error, except an attrs field with an unquoted number |
field~pattern | Regular expression. A pattern without regex characters is a substring match. Not allowed on numeric fields |
field IN (a,b,c) | Any of the values |
field:exists | The attr or text field is present and non-empty |
AND, OR, NOT, ( ) | Boolean logic. Adjacent terms mean AND |
Free text needs at least one letter or digit. Words of length 1 do not narrow the search on their own.
Stages#
The stage list is closed:
| Stage | Form |
|---|---|
where | where <expression> |
stats | stats <agg>[, <agg>...] [by f1, f2] |
timechart | timechart span=<n><s|m|h|d> <agg> [by field] (span at most 30 days, one aggregate, one optional by) |
top | top <n> <field> |
rare | rare <n> <field> |
sort | sort <field> ascending or sort -<field> descending |
limit | limit <n> with 1 <= n <= 10000 |
fields | fields f1, f2, ... |
Aggregates#
count(), count_if(<condition>), dc(f) (distinct count), sum(f), avg(f), min(f), max(f), p50(f), p90(f), p95(f), p99(f). Add as <alias>; an alias cannot contain .. All except count and count_if need a field.
Limits#
| Limit | Value |
|---|---|
| Query length | 8192 bytes |
| Nesting depth | 64 |
| Bound literals | 512 |
| Result row cap | 10,000 |
| Raw (no stats) result | 500 rows |
| Series in a timechart | 20, the rest fold into other |
| Execution time | 30 s |
| Rows read | 2,000,000,000 |
| Bytes read | 200 GiB |
| Maximum range | 31 days. The viewer role is limited to 7 days |
Errors#
The compiler returns an error with a 0-based byte offset pos and a message. The API answers 400 with position. Messages you can see:
| Message |
|---|
unterminated string |
unbalanced ')' |
unknown stage '<x>' (expected where, stats, timechart, top, rare, sort, limit, fields) |
unknown aggregate '<x>' (expected one of count, count_if, dc, sum, avg, min, max, p50, p90, p95, p99) |
<f>() needs a field |
invalid field name '<x>' |
expected integer 1..10000 |
query nested too deeply |
bad duration (e.g. 30s, 5m, 1h, 1d; max 30d) |
source= must be the first term of the query |
only one of stats/timechart/top/rare per query |
free-text search only works on source=events (use field=value for source=<name>) |
Not in CQL#
Joins, subqueries, field extraction, lookups, several sources in one query, and a time range in the query text. See Not supported.