
Alibabacloud Sls Cli Guidance
- 114 installs
- 8 repo stars
- Updated June 30, 2026
- aliyun/aliyun-sls-agent-skills
alibabacloud-sls-cli-guidance is a Claude skill that manages Alibaba Cloud SLS projects, logstores, indexes, log collection and queries using the aliyun CLI sls plugin.
About
This skill manages Alibaba Cloud SLS (Simple Log Service) resources using the aliyun CLI and its sls plugin. A developer uses it to create and manage projects, logstores, indexes, Logtail configs and machine groups, write logs, and query or SQL-analyze logs. It routes to per-operation reference files and includes a text-to-SQL path via SLS Copilot for natural-language log queries.
- Manages Alibaba Cloud SLS projects, logstores, indexes and log queries via aliyun-cli
- Covers Logtail pipeline configs, machine groups and put/query log operations
- Includes text-to-SQL log analytics via SLS Copilot
Alibabacloud Sls Cli Guidance by the numbers
- 114 all-time installs (skills.sh)
- Ranked #546 of 1,039 Cloud & Infrastructure skills by installs in the Skillselion catalog
- Data as of Jul 28, 2026 (Skillselion catalog sync)
alibabacloud-sls-cli-guidance capabilities & compatibility
Free skill; requires an Alibaba Cloud account with SLS (billed by Alibaba Cloud).
- Capabilities
- log management · log query · log collection · text to sql
- Use cases
- devops · data analysis
- Platforms
- macOS · Linux
- Runs
- Runs locally
- Pricing
- Bring your own API key
What alibabacloud-sls-cli-guidance says it does
Command-line interface for managing Alibaba Cloud Simple Log Service (SLS) resources including projects, logstores, and log queries.
Generate SQL from natural language via SLS Copilot
npx skills add https://github.com/aliyun/aliyun-sls-agent-skills --skill alibabacloud-sls-cli-guidanceAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 114 |
|---|---|
| repo stars | ★ 8 |
| Last updated | June 30, 2026 |
| Repository | aliyun/aliyun-sls-agent-skills ↗ |
What it does
Manage Alibaba Cloud SLS projects, logstores, indexes, log collection and queries via the aliyun CLI.
Who is it for?
Managing SLS projects, logstores, log collection and queries through the aliyun CLI.
When should I use this skill?
You need to create or manage SLS projects, logstores, indexes, Logtail configs, or query logs.
What you get
SLS resources are managed and logs queried through the correct aliyun CLI sls subcommands and reference workflows.
By the numbers
- 7 reference areas: project, logstore, index, query, put-logs, logtail, machine-group
Files
Aliyun SLS CLI
Command-line interface for managing Alibaba Cloud Simple Log Service (SLS) resources including projects, logstores, and log queries.
Prerequisites
Before starting, verify that aliyun-cli and sls plugin are installed:
aliyun version
aliyun sls versionExpected output: aliyun-cli-sls 0.1.0 (5e6288421) or similar
Installation (if not installed)
If the check fails, install aliyun-cli using one of these methods:
Option 1: Homebrew (macOS only)
brew install aliyun-cli
aliyun plugin install --names slsOption 2: Official installer (Linux and macOS)
# This method requires sudo permission to install to `/usr/local/bin/aliyun`.
sudo /bin/bash -c "$(curl -fsSL https://aliyuncli.alicdn.com/install.sh)"
aliyun plugin install --names slsConfiguration
Configure access credentials (using AccessKey example) and region:
aliyun configure set \
--access-key-id <access-key-id> \
--access-key-secret <access-key-secret> \
--region <region>Region examples: cn-hangzhou, cn-shanghai, cn-beijing, us-west-1
IMPORTANT: If credentials or region are not provided by the user, request them explicitly before proceeding with any operations.
For other authentication methods(StsToken|RamRoleArn|EcsRamRole|...), check: aliyun configure set --help
Common Operations
Below lists frequently used SLS operations. Read the corresponding reference file first before executing any of them.
| Reference | Related commands | Description |
|---|---|---|
| project | list-project create-project get-project update-project delete-project | Manage SLS projects (create, list, update, delete) |
| logstore | list-log-stores create-log-store get-log-store update-log-store delete-log-store | Manage logstores within a project |
| index | get-index create-index update-index delete-index | Configure indexes to enable query and SQL analytics |
| query-logs | get-logs-v2 get-histograms | Query and analyze logs with search or SQL |
| put-json-logs | put-json-logs | Write logs to a logstore |
| logtail-config | create-logtail-pipeline-config update-logtail-pipeline-config get-logtail-pipeline-config list-logtail-pipeline-config delete-logtail-pipeline-config | Manage Logtail pipeline configs for log collection (file input, JSON/delimiter/regex parsing, multiline, time extraction) |
| machine-group | create-machine-group update-machine-group get-machine-group list-machine-group delete-machine-group apply-config-to-machine-group remove-config-from-machine-group get-applied-configs | Manage machine groups and apply Logtail configs to them |
| text-to-sql | call-ai-tools | Generate SQL from natural language via SLS Copilot |
CLI Usage
Discover APIs
aliyun help sls
aliyun help sls <apiName>Validate command syntax (dry-run)
Add --cli-dry-run to validate parameters without executing:
aliyun sls list-project --offset 0 --size 50 --cli-dry-runOutput format
All commands return JSON by default. Use --cli-query with JMESPath expressions to filter output:
aliyun sls list-project --cli-query "projects[*].name"Global parameters
--cli-dry-run: Validate command without execution--cli-query <jmespath>: Filter output with JMESPath--region <region>: Override region--help: Show command help
Rules
1. Do not use deprecated APIs — use the current replacement so behavior stays supported and predictable.
| Deprecated | Use instead |
|---|---|
get-logs | get-logs-v2 |
2. Obtain explicit user approval before any delete — delete operations are irreversible. 3. Use `--cli-dry-run` first for destructive operations (delete, update). 4. Update APIs require full parameters — first call the corresponding Get API to retrieve current parameters, then include all meaningful parameters in the update call (including unchanged ones). Omitting parameters may reset them to defaults. 5. If a command fails: check required parameters with --cli-dry-run, verify credentials via aliyun configure list, read the error message, and compare your command with the corresponding reference file. If the sub-command is not recognized, upgrade the plugin via aliyun plugin update sls.
Index Configuration
Index configuration enables query and SQL analytics on a Logstore. You must create an index before using query syntax or SQL on logs.
Index types
- line: Full-text index. Enables searching log content by keyword (e.g.
"someWord"in query). - keys: Field index. Index specific log fields for filtering (e.g.
key: "value") and SQL analytics.
At least one of line or keys must be specified when calling create-index or update-index.
Field index types & options
| Type | Use for |
|---|---|
| text | String content; supports full-text and key-value search |
| long | Integer values |
| double | Floating-point values |
| json | JSON content; supports full-text and key-value search |
Options for all types:
- doc_value: Enable analytics so the field can be used in SQL (
GROUP BY,WHERE). Recommended: true. - alias: Alias name for the field (optional).
Additional options for text and json:
- caseSensitive: Case-sensitive matching (boolean).
- chn: Whether the content contains Chinese (boolean). Recommended: false if not needed.
- token: List of token delimiters for full-text split (e.g.
[","," ",";","=",...]).
Rules
1. Overwrite update: update-index replaces the entire index configuration — it does not merge or patch. Always call get-index first, then send the complete desired config with update-index. 2. Index changes (create or update) take effect within 1 minute.
Examples
Get current index configuration
aliyun sls get-index --project my-project --logstore my-logstoreCreate index: full-text only
aliyun sls create-index --project my-project --logstore my-logstore \
--line '{"chn":false,"caseSensitive":false,"token":[","," ",";","=","(",")","[","]","{","}",":","\n","\t","\r"]}'Create index: full-text + field indexes
For complex JSON, write the config to a file to avoid shell quoting issues:
cat > /tmp/keys.json << 'EOF'
{
"region": {
"doc_value": true,
"alias": "",
"type": "text",
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", ":", "\n", "\t", "\r"]
},
"end_time": {
"doc_value": true,
"alias": "",
"type": "long"
},
"request_time": {
"doc_value": true,
"alias": "",
"type": "double"
}
}
EOF
aliyun sls create-index --project my-project --logstore my-logstore \
--line '{"caseSensitive":false,"chn":false}' \
--keys "$(cat /tmp/keys.json)"Update index workflow
Always get-then-update to avoid losing existing configuration:
aliyun sls get-index --project my-project --logstore my-logstore
# Modify the returned JSON as needed, then pass the full config back:
aliyun sls update-index --project my-project --logstore my-logstore \
--line '{"caseSensitive":false,"chn":false}' \
--keys "$(cat /tmp/keys.json)"Delete index
aliyun sls delete-index --project my-project --logstore my-logstoreLogstore Operations
Manage logstores within an SLS project. A logstore is the unit for log collection, storage, query, and analytics.
Naming requirements
- Unique within the same project
- Lowercase letters, numbers, hyphens (
-), and underscores (_) only - Must start and end with a lowercase letter or number
- Length: 2–63 characters
Key parameters
| Parameter | Description | Default |
|---|---|---|
--ttl | Data retention in days | — (required) |
--shard-count | Number of read/write shards | — (required) |
--auto-split | Auto-split shards when write throughput exceeds limit | false |
--max-split-shard | Max shard count after auto-split | 256 |
--mode | standard (full analytics) or query (high-performance query, no SQL) | standard |
--hot-ttl | Hot storage days (0 = all hot) | 0 |
--append-meta | Append server-received time and client IP to log | false |
--enable-tracking | Enable web tracking (anonymous writes) | false |
Rules
1. Overwrite update: update-log-store does not merge — omitted parameters may reset to defaults. Always call get-log-store first, then pass all parameters back (only changing what you need).
Examples
List logstores
aliyun sls list-log-stores --project my-projectPagination: --offset (default 0) and --size (default 200, max 500).
Optional filters (can be combined):
--logstore-name "name"— fuzzy match on logstore name--mode standard|query— filter by mode--telemetry-type None|Metrics—Nonefor logs only,Metricsfor time-series only
aliyun sls list-log-stores --project my-project \
--logstore-name "app-metrics" --mode standard --telemetry-type Metrics \
--offset 0 --size 200Create logstore
aliyun sls create-log-store \
--project my-project \
--logstore-name my-logstore \
--ttl 30 \
--shard-count 2 \
--auto-split true \
--max-split-shard 256With encryption:
aliyun sls create-log-store \
--project my-project \
--logstore-name encrypted-logs \
--ttl 30 \
--shard-count 2 \
--encrypt-conf '{"enable":true,"encrypt_type":"default"}'Get logstore
aliyun sls get-log-store --project my-project --logstore my-logstoreUpdate logstore (get-then-update)
Step 1 — get current config:
aliyun sls get-log-store --project my-project --logstore testExample response:
{
"appendMeta": false,
"autoSplit": true,
"enable_tracking": true,
"hot_ttl": 60,
"infrequentAccessTTL": 0,
"logstoreName": "test",
"maxSplitShard": 256,
"mode": "standard",
"shardCount": 8,
"ttl": 60
}Step 2 — update with all parameters, only changing what you need (e.g. appendMeta → true):
aliyun sls update-log-store \
--project my-project \
--logstore test \
--logstore-name test \
--ttl 60 \
--append-meta true \
--auto-split true \
--enable-tracking true \
--hot-ttl 60 \
--infrequent-access-ttl 0 \
--max-split-shard 256 \
--mode standardDelete logstore
aliyun sls delete-log-store --project my-project --logstore my-logstoreLogtail Pipeline Config
Manage Logtail pipeline configs for log collection. A pipeline config defines what to collect (inputs), how to parse (processors), and where to send (flushers). After creation, you must create a machine group and apply the config to it for collection to take effect.
Key parameters
| Parameter | Description |
|---|---|
--project | Project name (required) |
--config-name | Config name (required) |
--inputs | Input plugin list (required) |
--processors | Processing plugin list (optional) |
--flushers | Output plugin list (required) |
--log-sample | Sample log content for reference (optional) |
Examples
Create: JSON log parsing
aliyun sls create-logtail-pipeline-config --project my-project \
--config-name json-log-config \
--inputs '{"Type":"input_file","FilePaths":["/app/**/output.json"],"EnableContainerDiscovery":false,"MaxDirSearchDepth":1,"FileEncoding":"utf8"}' \
--processors '{"Type":"processor_parse_json_native","SourceKey":"content"}' \
--flushers '{"Type":"flusher_sls","Logstore":"my-logstore","TelemetryType":"logs","Region":"cn-hangzhou","Endpoint":"cn-hangzhou-intranet.log.aliyuncs.com"}' \
--log-sample '{"status": 200, "latency": 4152, "method": "GetUserConfig", "user": "Alice"}'Create: Delimiter log parsing
aliyun sls create-logtail-pipeline-config --project my-project \
--config-name delimiter-log-config \
--inputs '{"Type":"input_file","FilePaths":["/app/**/access.log"],"EnableContainerDiscovery":false,"MaxDirSearchDepth":1,"FileEncoding":"utf8"}' \
--processors '{"Type":"processor_parse_delimiter_native","SourceKey":"content","Separator":"|","Quote":"\u0000","KeepingSourceWhenParseFail":true,"Keys":["remote_addr","time_iso8601","method","uri","protocol","status","sent_bytes","user_agent","latency"]}' \
--flushers '{"Type":"flusher_sls","Logstore":"my-logstore","TelemetryType":"logs","Region":"cn-hangzhou","Endpoint":"cn-hangzhou-intranet.log.aliyuncs.com"}' \
--log-sample '192.168.1.10 | 2026-03-24T10:52:01+08:00 | GET | /api/v1/products | HTTP/1.1 | 200 | 1240 | Mozilla/5.0 | 0.045'Create: Regex parsing + time parsing
For complex regex, write each processor to a separate file to avoid quoting issues:
cat > /tmp/processor_regex.json << 'ENDOFFILE'
{
"Type": "processor_parse_regex_native",
"SourceKey": "content",
"Regex": "(\\d+-\\d+-\\d+\\s\\S+)\\s\\S+\\s\\[(\\w+)]\\s\\S+\\s(\\w+)\\s\\S+\\s(\\S+)\\s\\S+\\s(.*)",
"Keys": ["time", "level", "func", "class", "content"]
}
ENDOFFILE
cat > /tmp/processor_time.json << 'ENDOFFILE'
{
"Type": "processor_parse_timestamp_native",
"SourceKey": "time",
"SourceFormat": "%Y-%m-%d %H:%M:%S,%f"
}
ENDOFFILE
aliyun sls create-logtail-pipeline-config --project my-project \
--config-name regex-time-config \
--inputs '{"Type":"input_file","FilePaths":["/app/**/app.log"],"EnableContainerDiscovery":false,"MaxDirSearchDepth":1,"FileEncoding":"utf8"}' \
--processors "$(cat /tmp/processor_regex.json)" \
--processors "$(cat /tmp/processor_time.json)" \
--flushers '{"Type":"flusher_sls","Logstore":"my-logstore","TelemetryType":"logs","Region":"cn-hangzhou","Endpoint":"cn-hangzhou-intranet.log.aliyuncs.com"}' \
--log-sample '2026-03-24 11:15:02,456 | [INFO] | main | com.app.OrderService | User [1001] placed an order.'Create: Regex + multiline + time parsing + timezone
cat > /tmp/input.json << 'ENDOFFILE'
{
"Type": "input_file",
"FilePaths": ["/app/**/app.log"],
"EnableContainerDiscovery": false,
"MaxDirSearchDepth": 1,
"FileEncoding": "utf8",
"Multiline": {
"Mode": "custom",
"StartPattern": "\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2},\\d{3}\\s\\|\\s\\[[A-Z]+\\]\\s\\|.*",
"UnmatchedContentTreatment": "single_line"
}
}
ENDOFFILE
cat > /tmp/processor_regex.json << 'ENDOFFILE'
{
"Type": "processor_parse_regex_native",
"SourceKey": "content",
"KeepingSourceWhenParseFail": true,
"Regex": "(\\d+-\\d+-\\d+\\s\\S+)\\s\\S+\\s\\[(\\w+)]\\s\\S+\\s(\\w+)\\s\\S+\\s(\\S+)\\s\\S+\\s(.*)",
"Keys": ["time", "level", "func", "class", "content"]
}
ENDOFFILE
cat > /tmp/processor_time.json << 'ENDOFFILE'
{
"Type": "processor_parse_timestamp_native",
"SourceKey": "time",
"SourceFormat": "%Y-%m-%d %H:%M:%S,%f",
"SourceTimezone": "GMT+08:00"
}
ENDOFFILE
aliyun sls create-logtail-pipeline-config --project my-project \
--config-name regex-multiline-config \
--inputs "$(cat /tmp/input.json)" \
--processors "$(cat /tmp/processor_regex.json)" \
--processors "$(cat /tmp/processor_time.json)" \
--flushers '{"Type":"flusher_sls","Logstore":"my-logstore","TelemetryType":"logs","Region":"cn-hangzhou","Endpoint":"cn-hangzhou-intranet.log.aliyuncs.com"}' \
--log-sample '2026-03-24 11:15:02,456 | [INFO] | main | com.app.OrderService | User [1001] placed an order.'Config structure
Input: input_file
| Field | Description |
|---|---|
FilePaths | File path patterns, supports ** glob; exactly 1 path required |
FileEncoding | File encoding: utf8, gbk |
MaxDirSearchDepth | Max directory search depth (0–1000, lower is better) |
EnableContainerDiscovery | Enable container auto-discovery |
Multiline | Multiline log config (see Multiline logs) |
Flusher: flusher_sls
| Field | Description |
|---|---|
Logstore | Target logstore name (required) |
TelemetryType | logs or metrics (required) |
Region | Region ID, e.g. cn-hangzhou (required) |
Endpoint | SLS endpoint, e.g. cn-hangzhou-intranet.log.aliyuncs.com (required) |
Processors
First processor must be a parsing plugin. After that, optionally add 1 time-parsing plugin, 1 filter plugin, and multiple desensitization plugins.
| Type | Description |
|---|---|
processor_parse_json_native | Parse JSON-formatted logs |
processor_parse_delimiter_native | Parse delimiter-separated logs |
processor_parse_regex_native | Parse logs with regex |
processor_parse_timestamp_native | Extract log time from a parsed field |
Multiline logs
When logs span multiple lines, configure Multiline in the input plugin to combine them. Set StartPattern to a regex matching the first line of each log entry.
| Field | Description |
|---|---|
Mode | custom for custom regex |
StartPattern | Regex matching the beginning of a log entry |
UnmatchedContentTreatment | How to handle unmatched lines: single_line (treat as individual logs) or discard |
Time parsing
Use processor_parse_timestamp_native to extract log time from a parsed field. Without it, log time defaults to collection time.
| Field | Description |
|---|---|
SourceKey | Field name containing the timestamp (required) |
SourceFormat | Time format string (required, see table below) |
SourceTimezone | Source timezone, e.g. GMT+08:00 (optional, defaults to machine timezone) |
Common time formats:
| Example | Format |
|---|---|
2017-12-11 15:05:07,456 | %Y-%m-%d %H:%M:%S,%f |
2006-01-02T15:04:05Z07:00 | %Y-%m-%dT%H:%M:%S |
Mon, 02 Jan 2006 15:04:05 MST | %A, %d %b %Y %H:%M:%S |
Rules
1. Overwrite update: update-logtail-pipeline-config replaces the entire config. Always call get-logtail-pipeline-config first, then send the complete config with update-logtail-pipeline-config. 2. Apply to machine group: A config alone does not collect logs. You must create a machine group and apply the config to it (see Apply Logtail config to machine group). 3. Processor ordering: The first processor must be a parsing plugin (JSON / delimiter / regex). Time-parsing must come after the parsing plugin. 4. For complex JSON parameters with special characters (regex, etc.), write to a temp file to avoid shell quoting issues. 5. For more Logtail pipeline config types (container stdout, syslog, MySQL, etc.), see CreateLogtailPipelineConfig API reference.
Machine Group
Manage machine groups within an SLS project. A machine group defines a set of machines for log collection. After creating a Logtail pipeline config, you must create a machine group and apply the config to it for collection to take effect.
Key parameters
| Parameter | Description |
|---|---|
--project | Project name (required) |
--group-name | Machine group name (required) |
--machine-identify-type | Identification type: ip (IP address) or userdefined (custom identifier) (required) |
--machine-list | List of machine IPs or custom identifiers (required) |
Rules
1. Overwrite update: update-machine-group replaces the entire machine list. Always call get-machine-group first, then pass all parameters back. 2. Deleting a machine group automatically unbinds all applied Logtail configs.
Examples
List machine groups
aliyun sls list-machine-group --project my-projectPagination: --offset (default 0) and --size (max 500).
Filter by name (partial match):
aliyun sls list-machine-group --project my-project --group-name "container"Create machine group (IP-based)
aliyun sls create-machine-group --project my-project \
--group-name container \
--machine-identify-type ip \
--machine-list 192.168.5.2Multiple machines:
aliyun sls create-machine-group --project my-project \
--group-name my-app-group \
--machine-identify-type ip \
--machine-list 192.168.5.2 192.168.5.3 192.168.5.4Create machine group (custom identifier)
aliyun sls create-machine-group --project my-project \
--group-name my-custom-group \
--machine-identify-type userdefined \
--machine-list my-app-identifierApply Logtail config to machine group
aliyun sls apply-config-to-machine-group --project my-project \
--config-name my-config \
--machine-group containerList applied configs on a machine group
aliyun sls get-applied-configs --project my-project --machine-group containerRemove Logtail config from machine group
aliyun sls remove-config-from-machine-group --project my-project \
--config-name my-config \
--machine-group containerProject Operations
Manage SLS projects. A project is the top-level resource that contains logstores, alerts, dashboards, and other SLS configurations.
Naming requirements
- Globally unique across all Alibaba Cloud regions
- Lowercase letters, numbers, and hyphens (
-) only - Must start and end with a lowercase letter or number
- Length: 3–63 characters
- Cannot be modified after creation
Key parameters
| Parameter | Description |
|---|---|
--project-name | Project name (required for create; also used as fuzzy filter for list) |
--description | Project description |
--recycle-bin-enabled | Enable recycle bin for deleted logstores (recommended: true) |
Examples
List projects
aliyun sls list-projectPagination: --offset (default 0) and --size (default 100, max 500).
Fuzzy filter by name:
aliyun sls list-project --project-name "my-project" --offset 0 --size 50Create project
aliyun sls create-project \
--project-name my-new-project \
--description "Project with recycle bin" \
--recycle-bin-enabled trueGet project
aliyun sls get-project --project my-projectUpdate project
aliyun sls update-project --project my-project --description "Updated description"Delete project
aliyun sls delete-project --project my-projectPut Logs
Write logs to a logstore using put-json-logs. Each --logs flag takes a JSON object representing one log entry.
Key parameters
| Parameter | Description |
|---|---|
--project | Target project name (required) |
--logstore | Target logstore name (required) |
--logs | JSON object for one log entry; repeat the flag to send multiple logs in one call |
--topic | Log topic tag (optional, used to classify logs) |
--source | Log source tag, e.g. server IP (optional) |
Rules
1. __time__ is a reserved field — its value must be a string of Unix timestamp in seconds (e.g. "1715769600", not 1715769600). If omitted, the server uses the receive time. 2. The target logstore must already exist. If you need to query or analyze these logs, an index must also be configured (see index.md).
Examples
Single log
aliyun sls put-json-logs --project my-project --logstore my-logstore \
--logs '{"__time__":"1715769600", "region":"cn-hangzhou", "content":"hello aliyun cli"}'Multiple logs in one call
Repeat --logs for each log entry:
aliyun sls put-json-logs --project my-project --logstore my-logstore \
--logs '{"__time__":"1715769600", "region":"cn-hangzhou", "content":"log entry 1"}' \
--logs '{"__time__":"1715769601", "region":"cn-hangzhou", "content":"log entry 2"}'With topic and source
aliyun sls put-json-logs --project my-project --logstore my-logstore \
--logs '{"level":"info","msg":"started"}' \
--topic "app-server" \
--source "192.168.1.10"Log Query
Use get-logs-v2 to query logs. Two modes: query (search) and SQL analytics.
Key parameters
| Parameter | Description |
|---|---|
--project | Project name (required) |
--logstore | Logstore name (required) |
--from | Start time, Unix timestamp in seconds, inclusive (required) |
--to | End time, Unix timestamp in seconds, exclusive (required) |
--accept-encoding | Must be lz4 (required) |
--query | Query expression; omit or "*" for all logs |
--line | Max rows per request (query mode page size) |
--offset | Start row for pagination (query mode, default 0) |
--reverse | true = newest first, false = oldest first (query mode only) |
Rules
1. Time range is left-closed right-open [from, to). 2. The logstore must have an index configured before querying (see index.md). 3. Result completeness: check meta.progress in the response — Complete means precise; otherwise retry for accurate results. 4. Pagination: only paginate when the result set is large (many rows or large log entries). For small result sets, fetch all at once to avoid unnecessary round-trips.
Query mode vs SQL mode
| Query mode | SQL mode | |
|---|---|---|
| When to use | Search and filter logs | Aggregation, complex filtering, or sorting with SQL |
| Syntax | --query '<query_syntax>' | `--query '<query_syntax> \ |
| Pagination | --offset + --line | LIMIT offset, count in SQL (default LIMIT 100) |
| Total count | Use get-histograms | select count(*) as total from log |
| Sort | --reverse true/false | ORDER BY <column> ASC/DESC (--reverse is ignored) |
Query syntax
* and "someWord" and key1: "value1" and (key2: "value2" or key3: "value3") not key4: "value4"*— match all"someWord"— full-text search (requires full-text index)key: "value"— field filter, contains match (requires field index)and/or/not— logic operators; use parentheses for grouping
SQL syntax
Format: <query_syntax> | SELECT ... FROM log WHERE ... ORDER BY ... LIMIT ...
- Left of
|: query syntax (e.g.*orstatus: "500") to pre-filter logs. - Right of
|: standard SQL; table is alwayslog(can be omitted when no join log). LIMIT offset, countfor pagination;LIMIT allto return everything (use only for small result sets).
Before writing complex SQL, or when a SQL query has failed, try text-to-sql to generate SQL from natural language. See text-to-sql.md.
Examples
Query mode: search all logs
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 --line 100Query mode: filter by field and keyword
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 --line 100 \
--query '* and "flowers" and season: "winter"'Query mode: pagination (page 2)
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 \
--query 'error' --offset 50 --line 50Query mode: get total count for pagination
aliyun sls get-histograms --project my-project --logstore my-logstore \
--from 1740000000 --to 1740003600 --query 'error'SQL mode: count
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 \
--query '* | select count(*) as total from log'SQL mode: filter + sort + pagination
# Page 1: first 100 rows, newest first
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 \
--query '* | select * from log where status = 500 order by __time__ desc limit 0, 100'
# Page 2
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 \
--query '* | select * from log order by __time__ desc limit 100, 100'SQL mode: aggregation
aliyun sls get-logs-v2 --project my-project --logstore my-logstore \
--accept-encoding lz4 --from 1740000000 --to 1740003600 \
--query 'status: "500" | select request_uri, count(*) as cnt from log group by request_uri order by cnt desc limit 20'Text-to-SQL
Use call-ai-tools with tool text_to_sql to generate SQL from natural language via SLS Copilot. Use it when:
- You need complex SQL and want the service to produce a high-quality statement from a natural-language question.
- A SQL query has failed (syntax error, wrong schema, or poor results) — retry by describing the intent in natural language.
Key parameters
| Parameter | Value / note |
|---|---|
--tool-name | text_to_sql (required) |
--region | Must be cn-shanghai |
--biz-region-id | Region of the target project; if unset, defaults to the region from `aliyun configure list \ |
Params (JSON body):
| Field | Description |
|---|---|
project | Target project name |
logstore | Target logstore name |
sys.query | Format: 当前时间: <current_time>,问题:<question_text> |
- `<current_time>`: human-readable time + Unix timestamp, e.g.
2026-03-18 14:04:11 1773813851 - `<question_text>`: the user's question in natural language
Example
aliyun sls call-ai-tools --tool-name text_to_sql --region cn-shanghai \
--biz-region-id cn-hangzhou \
--params '{
"project": "my-project",
"logstore": "my-logstore",
"sys.query": "当前时间: 2026-03-18 14:04:11 1773813851,问题:最近1小时status为500的请求数量是多少"
}'Next step
Pass the returned SQL into get-logs-v2 as --query (e.g. * | <returned_sql>). See query-logs.md for usage.