Simple Log Service lets you filter logs with search statements. Use results on their own or as input to analytic statements.
Prerequisites
To query logs, you must create an index.
Basic syntax
-
SLS Query Skill for intelligent log query and analysis: Query and analyze SLS log data with natural language in a local AI agent.
Query and analytic statements are separated by | in the format query statement|analytic statement. Example:
* | SELECT status, count(*) AS PV GROUP BY status
|
Statement type |
Description |
|
search statement |
Specifies search conditions: keywords, numeric values, numeric ranges, spaces, or an asterisk (*). If you specify a space or an asterisk (*), no filter is applied. Important
Specify no more than 30 conditions in a search statement. |
|
analytic statement |
Important
Analytic statements must follow a search statement. No FROM or WHERE clause is needed — SLS analyzes all data in the current Logstore by default. They are case-insensitive, do not support offset, and do not require a trailing semicolon (;). Performs calculations and statistical analysis on search results or all data. Supported functions and syntax: |
Writing search queries
To write a query statement:
Step 1: Choose search type
Step 2: Field data types
Step 3: Select a match mode
Search statement examples
Search results depend on log content and index configuration. The examples below use the following sample log and index configuration.
Text, double, and long types
Sample log
The following is a sample NGINX access log. The subsequent search statements are based on this log format:
__tag__:__receive_time__0 :1645499498
body_bytes_sent :3033
client_ip :11x xxx xxx4.26
host :www.wmxxxxxxxxxm
http_host :wxxxxxxxx xxxck.com
http_user_agent :Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.xxx xxx56 Safari/535.11
http_x_forwarded_for :11xx xxxxxxx.213
instance_id :i-01
instance_name :instance-02
network_type :vlan
owner_id :owner-01
referer :www.xxxxxxxxx.com
region :cn-shanghai
remote_addr :21x xx xxx76
remote_user :6f3x
request method :PUT POST
request_length :2414
request_method :GET
request_time :71
request_uri :/request/path-1/file-2
scheme :https
server_protocol :HTTP/2.0
slbid :slb-01
status :200
time_local :22/Feb/2022:03:11:08
upstream_addr :117.xxx.xxx6
upstream_response_time :27
upstream_status :200
user_agent :Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20120101 FireFox/29.0
vip_addr :2xx xxxxxxxx.33
vpc_id :195datxxxxxxxxxxxxxxxxx6d9c1f46f
Index configuration
Create indexes before querying logs. To check your index configuration, follow these steps.
-
On the query and analysis page of the logstore, select .
-
In the panel that appears, check whether field indexes are configured.
Common search
Fuzzy search
Search by delimiter
Keyword escaping
Json type
Sample log
{
"timestamp": "2025-03-21T14:35:18Z",
"level": "ERROR",
"service": {
"name": "payment-processor",
"version": "v2.8.1",
"environment": "production"
},
"error": {
"code": 5031,
"message": "Failed to connect to third-party API",
"details": {
"endpoint": "https://api.paymentgateway.com/v3/verify",
"attempts": 3,
"last_response": {
"status_code": 504,
"headers": {
"Content-Type": "application/json",
"X-RateLimit-Limit": "100"
}
}
}
},
"user": {
"id": "usr-9a2b3c4d",
"session": {
"id": "sess-zxy987",
"device": {
"type": "mobile",
"os": "Android 14",
"network": "4G"
}
}
},
"trace": {
"correlation_id": "corr-6f5e4d3c",
"span_id": "span-00a1b2"
}
}
Index configuration
Create indexes before querying logs. To check your index configuration, follow these steps.
-
On the query and analysis page of the logstore, select .
-
In the panel that appears, check whether field indexes are configured.
Examples
|
Goal |
Search statement |
|
Search for logs that record request errors. |
|
|
Search for all requests from the user whose ID is |
|
|
Search for logs from user |
|
FAQ
Query returns no logs
What to do if a query returns no logs
JSON log issues
FAQ about querying and analyzing JSON logs
Troubleshoot query errors
Related topics
-
Log query examples
-
Query and analyze JSON logs covers examples for JSON fields with object or array values.