Simple Log Service lets you run a search statement to filter logs. You can use the search results independently or as input to an analytic statement for more complex analysis.
Prerequisites
To query logs, you must create an index.
Basic syntax
SLS Query Skill for intelligent log query and analysis: SLS provides Agent Skill, which lets you use natural language to query and analyze SLS log data in a local AI agent.
Query statements and analytic statements are separated by | in the format query statement|analytic statement. The following is an example:
* | SELECT status, count(*) AS PV GROUP BY statusStatement type | Description |
search statement | Specifies the search conditions. Conditions can be 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 You must use an analytic statement with a search statement. You do not need to specify a FROM or WHERE clause in an analytic statement because the service analyzes all data in the current Logstore by default. Analytic statements are case-insensitive, do not support offset, and do not require a trailing semicolon (;). Performs calculations and statistical analysis on the search results or all data. SLS supports the following analytic 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
A search statement returns different results depending on the log content and index configuration. The examples in this topic are based on the following sample log and index configuration.
Text, double, and long types
Sample log
This topic demonstrates common search statements by using an NGINX access log.

Index configuration
You must create indexes before you can query logs. To check your index configuration, perform the following 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
You must create indexes before you can query logs. To check your index configuration, perform the following 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
See Query and analyze JSON logs for examples of querying JSON logs where field values are JSON objects or arrays.