Skip to main content

Query syntax

Queries let you filter logs in the Log Explorer, in alert rules, and in dashboards. You query OpenTelemetry attributes β€” the ones captured by your collector. See Understanding a log entry for an overview of available attributes.

tip

In the Log Explorer, type your query then press Ctrl + Enter to run it. Time periods are controlled by the selector in the top right corner, not in the query itself.

Syntax reference​

Basic field queries​

SyntaxMeaningExample
field:valueExact matchservice_name:syslog
field:"multi word value"Exact phrasebody.message:"connection refused"
field:value*Prefix wildcardhost.name:prod-*
field:*value*Containsbody.message:*timeout*
field:*Field existscloud.region:*
warning

Queries are case-sensitive. service_name:Syslog is not the same as service_name:syslog.

Boolean operators​

OperatorMeaningExample
ANDBoth conditions must matchservice_name:nginx AND severity_number:[17 TO *]
OREither condition must matchservice_name:nginx OR service_name:apache
NOTExclude matching logsservice_name:syslog AND NOT host.name:test-*
( )Group conditionsservice_name:nginx AND (severity_text:ERROR OR severity_text:FATAL)

Numeric ranges​

SyntaxMeaningExample
[min TO max]Inclusive rangeseverity_number:[13 TO 16] (WARNING)
{min TO max}Exclusive rangeseverity_number:{12 TO 17} (WARNING, exclusive bounds)
[min TO *]Greater than or equalseverity_number:[17 TO *] (ERROR and above)
[* TO max]Less than or equalseverity_number:[* TO 12] (INFO and below)

Common fields​

FieldDescriptionExample values
service_nameService that produced the logsyslog, nginx, payments-api
severity_numberNumeric severity (see glossary)9 (INFO), 17 (ERROR), 21 (FATAL)
severity_textText severityDEBUG, INFO, WARNING, ERROR, FATAL
host.nameSource hostnameprod-web-03, db-replica-01
body.messageLog message contentFree text
cloud.regionCloud regionus-east-1, eu-west-1
deployment.environmentEnvironmentprod, staging, dev

Examples by use case​

Infrastructure β€” find errors on a specific host​

host.name:prod-web-03 AND severity_number:[17 TO *]

Security β€” detect brute force login attempts​

body.message:*"authentication failure"* AND service_name:sshd

Application β€” find database connection issues​

body.message:*"connection refused"* AND service_name:payments-api

Multi-service investigation β€” correlate errors across services​

severity_text:ERROR AND (service_name:api-gateway OR service_name:payments-api OR service_name:user-service)

Exclude noise β€” filter out health checks​

service_name:nginx AND NOT body.message:*healthcheck* AND NOT body.message:*ping*

Common mistakes​

MistakeProblemFix
Service_Name:syslogWrong caseservice_name:syslog
service_name: syslogSpace after colonservice_name:syslog
severity_number:>17Invalid range syntaxseverity_number:[17 TO *]
message:failedWrong field namebody.message:*failed*
Including time in queryTime is set via the UIUse the time period selector instead

What's next?​