
Alibabacloud Sls Index Config Management
- 105 installs
- 208 repo stars
- Updated August 4, 2026
- aliyun/alibabacloud-aiops-skills
alibabacloud-sls-index-config-management is a Claude skill that inspects, creates, updates, deletes, generates and optimizes Alibaba Cloud SLS Logstore index configurations via the aliyun CLI.
About
This skill manages index configuration for Alibaba Cloud SLS (Simple Log Service) Logstores. A developer uses it to inspect, create, update or delete a Logstore index, generate an index config from sample logs, or optimize an existing index for a given query workload, throughput and storage cost. All operations run through the aliyun CLI and output both the full JSON config and a human-readable summary.
- Inspects, creates, updates and deletes SLS Logstore indexes via the aliyun CLI
- Generates an index config from structured log samples
- Optimizes an existing index for query/SQL workload, cost and write throughput
Alibabacloud Sls Index Config Management by the numbers
- 105 all-time installs (skills.sh)
- Ranked #557 of 1,039 Cloud & Infrastructure skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
alibabacloud-sls-index-config-management capabilities & compatibility
Free skill; requires an Alibaba Cloud account with SLS (billed by Alibaba Cloud).
- Capabilities
- log index management · index optimization · config generation
- Use cases
- devops · data analysis
- Runs
- Runs locally
- Pricing
- Bring your own API key
What alibabacloud-sls-index-config-management says it does
Alibaba Cloud SLS (Simple Log Service) index configuration manager skill.
generate an index configuration from user-provided structured log samples, and optimize an existing index configuration for given query/SQL workloads, write throughput, and storage cost
npx skills add https://github.com/aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-index-config-managementAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 105 |
|---|---|
| repo stars | ★ 208 |
| Last updated | August 4, 2026 |
| Repository | aliyun/alibabacloud-aiops-skills ↗ |
What it does
Manage and optimize Alibaba Cloud SLS Logstore index configurations for query, SQL, cost and write throughput.
Who is it for?
Managing and optimizing SLS Logstore index configurations for query and cost on Alibaba Cloud.
When should I use this skill?
You need to view, build, change, or optimize an SLS Logstore index configuration.
What you get
A Logstore index configuration is created, updated or optimized and returned as complete JSON plus a summary.
By the numbers
- 3 index scenarios: manage, generate-from-logs, optimize
Files
Alibaba Cloud SLS Index Configuration Manager
Scenario Description
Use this skill for SLS Logstore index configuration.
This file only covers trigger-time setup, routing, and cross-scenario safety. Read only the reference document needed for the user's request.
---
Prerequisites
Install Aliyun CLI
Run aliyun version to verify the version is >= 3.3.8. If not installed or outdated, follow references/cli-installation-guide.md to install or update.
Ensure AI Mode Enabled
Before executing any SLS API commands, enable AI-Mode, set User-Agent, and update plugins:
aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-sls-index-config-management"
aliyun plugin updateCheck Alibaba Cloud credentials configured
Run aliyun configure list to check if credentials are configured. If no valid profile is shown, STOP here and ask the user to run aliyun configure outside of this session.
Security rules:
- NEVER read, echo, or print AK/SK values
- NEVER ask the user to paste AK/SK into the conversation
- ONLY use
aliyun configure listto check credential status
---
RAM Permission Requirements
On Unauthorized error, surface references/ram-policies.md to the user. Do not retry with a different account without explicit confirmation.
---
Routing the Request
After environment and credential checks, classify the user's request and follow the matching reference:
| If the user wants to … | Go to |
|---|---|
View / create / update / delete an index, or change a single field, TTL, max_text_len, full-text on-off, log_reduce, etc. | references/manage-index-config.md |
| Build an index for a Logstore that has none, or rebuild from scratch using user-provided structured log samples | references/generate-index-from-logs.md |
| Adjust an existing index to support a new query / SQL, reduce cost, or improve write throughput | references/optimize-index-config.md |
Mixed requests are common (e.g. "generate an index for these logs and then update it on Logstore X"). Read the relevant scenario docs in order.
---
Global Rules
- No writes without the scenario reference. Before any write operation, read the relevant reference document and follow its confirmation, full-body, rollback, and timing rules.
- Use exact SLS CLI names. Product is
sls; subcommands and flags are kebab-case. Use references/acceptance-criteria.md only when validating command shape or debugging CLI invocation issues.
Output Format
Every time you present an index configuration to the user — whether from a read (get-index), after a write (create-index / update-index), or during generation/optimization — output both:
1. Complete JSON — the full get-index JSON response (or the equivalent JSON body you are about to submit for a write). Wrap it in a fenced json code block so the user can copy-paste it directly. 2. Human-readable summary
Put the Complete JSON first, then the summary. The summary helps the user understand the config at a glance; the JSON is the authoritative, machine-readable reference they can use for scripting, version control, or future update-index calls.
---
Cleanup
Whether operations succeed or fail, you MUST disable AI-Mode before ending the session:
aliyun configure ai-mode disable---
Reference Documents
| Document | Description |
|---|---|
| references/manage-index-config.md | Index config format and get / create / update / delete command examples |
| references/generate-index-from-logs.md | Infer a complete index configuration from user-provided structured log samples |
| references/optimize-index-config.md | Optimize an existing index for query/SQL workload, cost, and write throughput |
| references/related-apis.md | GetIndex / CreateIndex / UpdateIndex / DeleteIndex API & CLI reference |
| related_apis.yaml | Machine-readable dependent API metadata for this skill |
| references/ram-policies.md | Minimum and complete RAM policies for index management |
| references/acceptance-criteria.md | CLI invocation acceptance tests |
| references/cli-installation-guide.md | Aliyun CLI install, auth modes, profiles |
Acceptance Criteria: sls-index-config-manager
Scenario: SLS Index Configuration Management Purpose: Skill testing acceptance criteria
---
Correct CLI Invocation Patterns
1. Command Format — verify product and API name
CORRECT
aliyun sls get-index --project my-project --logstore my-logstore
aliyun sls create-index \
--project my-project --logstore my-logstore \
--line "$(cat /tmp/line.json)" \
--keys "$(cat /tmp/keys.json)"
aliyun sls delete-index --project my-project --logstore my-logstoreINCORRECT — Wrong product name
aliyun log get-index --project my-project --logstore my-logstore
aliyun logservice create-index --project p --logstore lWhy: Product name is sls, not log, logservice, aliyunlog, or aliyun-sls.
2. Parameter Format
CORRECT — Kebab-case sub-command and flags
aliyun sls update-index \
--project my-project --logstore my-logstore \
--line "$(cat /tmp/line.json)" \
--keys "$(cat /tmp/keys.json)" \
--max-text-len 4096INCORRECT — PascalCase sub-command or flags
aliyun sls UpdateIndex --Project p --Logstore l --Keys ...
aliyun sls GetIndex --Project pWhy: The SLS plugin uses kebab-case for both sub-commands (get-index, create-index, update-index, delete-index) and flags (--project, --logstore, --line, --keys, --max-text-len).
INCORRECT — JSON --params blob
aliyun sls update-index --params '{"Project":"p","Logstore":"l","Keys":{...}}'Why: The CLI takes individual flags, not a JSON --params blob.
3. Index Body Passing — always via file
CORRECT — Write JSON to file, then pass with $(cat ...)
cat > /tmp/line.json <<'EOF'
{
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
}
EOF
cat > /tmp/keys.json <<'EOF'
{
"status": { "type": "long", "doc_value": true },
"request_uri": {
"type": "text",
"doc_value": true,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", ":", "/", "\n", "\t", "\r"]
}
}
EOF
aliyun sls create-index \
--project my-project --logstore my-logstore \
--line "$(cat /tmp/line.json)" \
--keys "$(cat /tmp/keys.json)"INCORRECT — Inline multi-line JSON with shell-special characters
aliyun sls create-index --project p --logstore l \
--keys '{
"request_uri": {"type":"text","token":[",", " ", "\n", "\t"]}
}'Why: Tokenizer arrays usually contain backslash escapes (\n, \t, \r) and quotes. Inline multi-line JSON in the shell breaks quoting; always serialize to a file first.
4. UpdateIndex — complete config replacement
CORRECT — Submit the complete final config
aliyun sls get-index --project my-project --logstore my-logstore > /tmp/current.json
# Prepare /tmp/line.json and /tmp/keys.json as the final complete config.
aliyun sls update-index \
--project my-project --logstore my-logstore \
--line "$(cat /tmp/line.json)" \
--keys "$(cat /tmp/keys.json)" \
--max-text-len 2048INCORRECT — Sending only a partial field fragment
aliyun sls update-index \
--project my-project --logstore my-logstore \
--keys '{"new_field":{"type":"long","doc_value":true}}'Why: update-index is overwrite — submitting only keys drops line, max_text_len, log_reduce, and every existing field that was not re-included.
5. CreateIndex vs UpdateIndex — pick by current state
CORRECT — Branch on whether get-index succeeds
if aliyun sls get-index --project p --logstore l > /tmp/cur.json 2>/tmp/err; then
aliyun sls update-index \
--project p --logstore l \
--line "$(cat /tmp/line.json)" \
--keys "$(cat /tmp/keys.json)"
else
grep -q IndexConfigNotExist /tmp/err && \
aliyun sls create-index \
--project p --logstore l \
--line "$(cat /tmp/line.json)" \
--keys "$(cat /tmp/keys.json)"
fiINCORRECT — Always calling create-index
aliyun sls create-index --project p --logstore l --line "..." --keys "..."Why: If an index already exists, create-index fails with IndexAlreadyExist. Always inspect first.
6. DeleteIndex — explicit confirmation required
CORRECT — Confirm and capture a snapshot before deleting
aliyun sls get-index --project p --logstore l > /tmp/index-backup-$(date +%s).json
# After explicit user confirmation:
aliyun sls delete-index --project p --logstore lINCORRECT — Chaining delete-index after a write
aliyun sls update-index --project p --logstore l --line "..."
aliyun sls delete-index --project p --logstore lWhy: delete-index removes the entire index and breaks query / SQL on that Logstore. The skill never chains it after other writes and must obtain explicit user confirmation.
7. Authentication — never expose credentials
CORRECT — Verify credential profile via default credential chain
aliyun configure listINCORRECT — Passing AK/SK directly in the command
aliyun sls update-index \
--access-key-id LTAI5tXXXX \
--access-key-secret 8dXXXX \
--project p --logstore l --line "..."Why: Credentials must come from the configured profile, environment variables, STS, or RAM role — never be typed into the command line.
INCORRECT — Reading or printing raw credentials
aliyun configure get # FORBIDDEN: may expose credential details
cat ~/.aliyun/config.json # FORBIDDEN: may expose credential detailsINCORRECT — Any command that prints environment credentials
echo $ALIBABA_CLOUD_ACCESS_KEY_ID # FORBIDDEN
printenv | grep -i credential # FORBIDDEN
env | grep -i access_key # FORBIDDEN8. API Names — verify exact sub-command
CORRECT
get-index # OpenAPI Action: GetIndex
create-index # OpenAPI Action: CreateIndex
update-index # OpenAPI Action: UpdateIndex
delete-index # OpenAPI Action: DeleteIndexINCORRECT
GetIndex # PascalCase is the Action name, not the CLI sub-command
getIndex # Wrong casing
get_index # Wrong separator (snake_case)
getindex # Missing separator
describe-index # Wrong verb — SLS uses get-, not describe-
put-index # Wrong verb — use update-index
modify-index # Not a real sub-command
get-log-index # Not a real sub-command — use get-index9. Region Parameter
CORRECT
--region cn-hangzhou
--region cn-shanghai
--region ap-southeast-1INCORRECT
--region hangzhou # Missing country prefix
--region cn-hangzhou-1 # Not a real region ID
--region-id cn-hangzhou # CLI global flag is --region, not --region-idWorkflow Checklist
When the skill executes a write, it must satisfy all of:
- [ ]
aliyun configure listwas run and returned a configured profile. - [ ] AI mode was enabled (
aliyun configure ai-mode enable). - [ ]
get-indexwas called and the response was captured to a file before any write. - [ ] Index body was written to
/tmp/<name>.json(not inlined). - [ ]
update-indexbody is the full desired configuration, not a partial fragment. - [ ] For
delete-index, the user gave explicit confirmation and a backup file was written. - [ ] AI mode was disabled at the end of the session (
aliyun configure ai-mode disable).
Aliyun CLI Installation & Configuration Guide
Complete guide for installing and configuring Aliyun CLI for the index configuration manager skill.
Aliyun CLI 3.3.8+: Supports installing and using all published Alibaba Cloud product plugins.
Make sure to upgrade to 3.3.8 or later for full plugin ecosystem coverage, including the sls plugin used by this skill.Installation
macOS
Using Homebrew (Recommended)
brew install aliyun-cli
brew upgrade aliyun-cli
aliyun versionUsing Binary
wget https://aliyuncli.alicdn.com/aliyun-cli-macosx-latest-amd64.tgz
tar -xzf aliyun-cli-macosx-latest-amd64.tgz
sudo mv aliyun /usr/local/bin/
aliyun versionLinux
Debian/Ubuntu and CentOS/RHEL (amd64)
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz
tar -xzf aliyun-cli-linux-latest-amd64.tgz
sudo mv aliyun /usr/local/bin/
aliyun versionARM64 Architecture
wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-arm64.tgz
tar -xzf aliyun-cli-linux-latest-arm64.tgz
sudo mv aliyun /usr/local/bin/Windows
Using Binary
1. Download from <https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip> 2. Extract the ZIP 3. Add the directory to your PATH 4. Open a new Command Prompt or PowerShell 5. Verify with aliyun version
Using PowerShell
Invoke-WebRequest -Uri "https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip" -OutFile "aliyun-cli.zip"
Expand-Archive -Path aliyun-cli.zip -DestinationPath C:\aliyun-cli
$env:Path += ";C:\aliyun-cli"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
aliyun versionInstall / Update the SLS Plugin
aliyun plugin update
aliyun plugin install --names sls # only if `aliyun sls --help` says "command not found"
aliyun sls --helpConfiguration
Credential Setup
The skill may check whether credentials exist, but it must not read or print credential values. Use only this command inside the agent session:
aliyun configure listIf no valid profile is listed, stop and ask the user to configure credentials in their own terminal. The user can run the interactive wizard:
aliyun configureAliyun CLI supports AK, StsToken, RamRoleArn, EcsRamRole, RsaKeyPair, and RamRoleArnWithEcs authentication modes. Pick the mode that matches the deployment environment:
| Mode | Typical use |
|---|---|
| AK | Local development and manually managed RAM users |
| StsToken | Temporary credentials and CI/CD jobs |
| RamRoleArn | Cross-account or role-assumption workflows |
| EcsRamRole | Automation running on ECS with an attached RAM role |
| RsaKeyPair | RSA key-pair authentication |
| RamRoleArnWithEcs | ECS role plus cross-account role assumption |
Credential priority, highest first:
1. --profile <name> command-line flag. 2. ALIBABA_CLOUD_PROFILE. 3. Environment credentials already present in the process environment. 4. The active profile in the Aliyun CLI config file. 5. ECS instance RAM role.
When multiple profiles are configured, use a profile-specific command rather than changing global state:
aliyun sls get-index --profile projectA --project p --logstore lDo not run commands that display secret values, such as aliyun configure get, cat ~/.aliyun/config.json, or commands that print credential environment variables.
Verification
Test Authentication
aliyun ecs describe-regionsSuccessful invocation returns a JSON list of regions. Any of the following errors indicates a credential issue:
InvalidAccessKeyId.NotFoundSignatureDoesNotMatchInvalidSecurityToken.ExpiredForbidden.RAM
Test SLS plugin & permissions
aliyun sls get-index --project <project> --logstore <logstore>- Success → both CLI and
log:GetIndexare working. IndexConfigNotExist(404) → CLI is working; the Logstore simply has no index. Proceed to the create-index workflow.Unauthorized→ grant the policies in ram-policies.md.
Security Best Practices
1. Use RAM users, not the root account. 2. Principle of least privilege — grant only the actions in ram-policies.md that match the user's task. 3. Rotate access keys regularly. 4. Prefer STS or ECS RAM Role for temporary or in-cloud workflows. 5. Never commit `~/.aliyun/config.json`; add it to .gitignore. 6. chmod 600 ~/.aliyun/config.json to restrict local file permissions.
Troubleshooting
Issue: Command Not Found
which aliyun
echo $PATHReinstall or add the binary directory to PATH.
Issue: aliyun sls --help says "command not found"
aliyun plugin update
aliyun plugin install --names slsIssue: Authentication Failed
aliyun configure list
aliyun ecs describe-regionsIssue: Permission Denied (Forbidden.RAM)
Check that the RAM user has the policies described in ram-policies.md.
Issue: Wrong Region
aliyun sls get-index --region cn-shanghai --project <project> --logstore <logstore>A Project lives in exactly one region; a region mismatch returns ProjectNotExist.
Advanced Configuration
Custom Endpoint
export ALIBABA_CLOUD_LOG_ENDPOINT=<custom-or-internal-sls-endpoint>Proxy Settings
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1,.aliyuncs.comTimeout Settings
export ALIBABA_CLOUD_CONNECT_TIMEOUT=30
export ALIBABA_CLOUD_READ_TIMEOUT=30References
- Official Documentation: <https://help.aliyun.com/zh/cli/>
- RAM Console: <https://ram.console.aliyun.com/>
- Access Key Management: <https://ram.console.aliyun.com/manage/ak>
- Aliyun CLI source: <https://github.com/aliyun/aliyun-cli>
Generate Index Configuration from Log Samples
Use this reference when the user provides multiple structured log samples and wants an SLS field index config inferred from them.
For direct index config operations and CLI examples, see manage-index-config.md. For workload/cost/throughput tuning on an existing index, see optimize-index-config.md.
Workflow
1. Run get-index and save the current index config as a backup if an index exists. If IndexConfigNotExist is returned, skip the backup and plan to use create-index. 2. Analyze the user-provided samples and infer each field's SLS index type. 3. Generate the complete final index config. 4. Output the final index config and the matching create-index or update-index CLI command.
Generation Rules
Use user-provided structured log samples. The expected shape is a single-level key/value map: { "field": value, ... }.
Generate keys only by default. Do not generate a full-text line index unless the user asks for full-text keyword search.
For each top-level field:
1. Inspect all non-empty sample values for that field. 2. Infer the narrowest compatible SLS type. 3. Add one keys.<field> entry. 4. Set doc_value: false unless the user explicitly says the field is needed for SQL analytics (SELECT, WHERE, GROUP BY, ORDER BY, aggregations).
Do not make assumptions from field names alone. For example, do not set doc_value: true just because a field is named status, request_time, or user_id.
Type Inference
| Observation | SLS type | Notes |
|---|---|---|
| Every non-empty value is an integer and fits int64 | long | Numeric strings are allowed if all values are integer-shaped. |
| Every non-empty value is numeric and at least one value has a decimal | double | Use only when all values are numeric. |
| Every non-empty value parses as a JSON object string | json | Configure only one explicit JSON level by default. |
| Anything else | text | Safe fallback for mixed values, booleans, IDs, and free text. |
Text defaults:
{
"type": "text",
"doc_value": false,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
}JSON Fields
For an SLS json field, do not use index_all by default. Parse the JSON object strings and configure only first-level scalar keys under json_keys.
Rules:
- Infer
json_keys.<key>.typefrom that first-level key's sample values. - Use only
text,long, ordoubleinsidejson_keys. - Do not configure
tokeninsidejson_keys; text subkeys use the parentjsonfield's
tokenizer.
- Do not recurse into nested objects/arrays unless the user explicitly asks.
Example for field extra:
{
"type": "json",
"doc_value": false,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ":", "-", "\n", "\t", "\r"],
"json_keys": {
"trace_id": {
"type": "text",
"doc_value": false,
"caseSensitive": false,
"chn": false
},
"region": {
"type": "text",
"doc_value": false,
"caseSensitive": false,
"chn": false
},
"cost": {
"type": "double",
"doc_value": false
}
}
}Output
Return a concise field inference summary, the complete generated index config, and the matching create-index or update-index command from manage-index-config.md.
Example Output
Example keys config (three representative field types):
{
"request_uri": {
"type": "text",
"doc_value": false,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
},
"status": {
"type": "long",
"doc_value": false
},
"extra": {
"type": "json",
"doc_value": false,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ":", "-", "\n", "\t", "\r"],
"json_keys": {
"trace_id": { "type": "text", "doc_value": false, "caseSensitive": false, "chn": false },
"cost": { "type": "double", "doc_value": false }
}
}
}Manage Index Configuration
Use this reference for direct SLS Logstore index work: view, create, replace, or delete an index configuration.
| Operation | CLI subcommand |
|---|---|
| Create | aliyun sls create-index |
| Read | aliyun sls get-index |
| Update | aliyun sls update-index |
| Delete | aliyun sls delete-index |
Use aliyun help sls <subcommand> for command-specific flags and examples, such as aliyun help sls create-index.
Core Rules
create-indexandupdate-indexuse nearly the same flags. Usecreate-indexwhen no index
exists; use update-index when replacing an existing config.
update-indexoverwrites the whole index config. The submittedline/keysfiles must
represent the complete final config, not a partial fragment.
- At least one of
line,keys, orscan_indexmust be present. - Object-valued parameters such as
lineandkeysshould be written to/tmp/*.jsonand
passed with $(cat /tmp/file.json).
- Index writes apply only to new logs after propagation, usually within ~1 minute.
Index Basics
SLS index config is mainly line + keys.
| Part | Purpose |
|---|---|
line | Full-text index. Enables keyword search such as "error". |
keys | Field indexes. Enables field filters such as status: 500 and SQL analytics. |
Common field types:
| Type | Use for |
|---|---|
text | Strings and keyword/equality search |
long | Integers |
double | Floating-point values |
json | JSON object/array strings |
Common field options:
doc_value: enable SQL analytics for the field. Use it for fields inSELECT,WHERE,
GROUP BY, ORDER BY, or aggregations.
caseSensitive: case-sensitive text matching.chn: Chinese tokenization. Keepfalseunless Chinese keyword search is needed and user requires it.token: token delimiters for full-text/text fields.index_all,max_depth,json_keys: JSON indexing controls.
Examples
Each example shows the JSON file(s), then the matching create-index and update-index commands.
Full-Text Only
/tmp/sls-index-line.json:
{
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
}aliyun sls create-index \
--project <project> --logstore <logstore> \
--line "$(cat /tmp/sls-index-line.json)" \
--max-text-len 2048Full-Text + Field Indexes
/tmp/sls-index-line.json:
{
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
}/tmp/sls-index-keys.json:
{
"status": { "type": "long", "doc_value": true },
"request_time": { "type": "double", "doc_value": true },
"request_uri": {
"type": "text",
"doc_value": true,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", ":", "/", "\n", "\t", "\r"]
}
}aliyun sls update-index \
--project <project> --logstore <logstore> \
--line "$(cat /tmp/sls-index-line.json)" \
--keys "$(cat /tmp/sls-index-keys.json)" \
--max-text-len 2048Common Errors
| Error | Action |
|---|---|
ParameterInvalid | Check and Fix the parameter value according to the error message. |
Unauthorized | Check ram-policies.md. |
Optimize Index Configuration
Adjust an existing SLS index config for a query, SQL statement, write throughput, or storage cost.
Process
1. Run get-index and save the current index config as a backup. 2. Analyze the user's requirement, the current index config, and any relevant context such as query statements, SQL statements, sample fields, cost concerns, or write-throughput concerns. 3. Generate the complete optimized line / keys config. 4. Produce an optimization report explaining what changed and why. 5. Provide the update-index CLI command that submits the complete optimized config.
Principles
- Missing fields in query: if a query references a field that is not in
keys, add that field
to the field index.
- Missing SQL fields: if SQL uses a field in
SELECT,WHERE,GROUP BY,ORDER BY, or an
aggregation, the field index needs doc_value: true.
- No-token fields: for identifier-like fields that do not need tokenization, such as
request_id, trace_id, span_id, user_id, or exact-match IDs, remove unnecessary token delimiters. Keep tokenization minimal for exact-match fields.
- Chinese indexing: prefer
chn: false. Enable Chinese tokenization only when the user
explicitly needs Chinese keyword search on that field.
- Long unstructured text: for long, unstructured fields that are unlikely to be used in SQL
analysis, such as content, message, or raw_payload, set doc_value: false to reduce storage overhead.
- Deep JSON fields: control JSON index depth carefully. For very deep JSON fields, avoid
indexing excessive depth; generally do not exceed 5 levels unless the user explicitly needs it.
- Integer fields: if all observed values for a field are integers, prefer
longovertext.
Guardrails
- Keep the user's required query or SQL working; do not remove needed indexes to save cost unless
the user accepts that tradeoff.
update-indexreplaces the full config. Submit the complete finalline/keysconfig, not
only the optimized field.
- Explain any behavior change, especially removing tokenization, disabling
doc_value, reducing
JSON depth, or turning off Chinese tokenization.
Output
- Optimized
line/keysJSON files. - Brief optimization report: only list meaningful changes and why.
- Complete
aliyun sls update-index ...command.
RAM Policies - SLS Index Configuration Manager
Required Permissions
| CLI Command | API Action |
|---|---|
get-index | log:GetIndex |
create-index | log:CreateIndex |
update-index | log:UpdateIndex |
delete-index | log:DeleteIndex |
Resource: acs:log:{regionId}:{accountId}:project/{ProjectName}/logstore/{LogstoreName}
ARN placeholders: {regionId} (e.g. cn-hangzhou, or *), {accountId} (UID or *), {ProjectName} (or *), {LogstoreName} (or *).
Minimum RAM Policy (read-only)
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": ["log:GetIndex"],
"Resource": "acs:log:*:*:project/<project-name>/logstore/<logstore-name>"
}
]
}Complete RAM Policy
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"log:GetIndex",
"log:CreateIndex",
"log:UpdateIndex",
"log:DeleteIndex"
],
"Resource": "acs:log:*:*:project/<project-name>/logstore/<logstore-name>"
}
]
}Use logstore/* to match all Logstores under a project, or project/* to match all projects.
Grant only the actions needed: start with GetIndex for inspection, add write actions when needed, add DeleteIndex only when the user explicitly requests deletion.
Related APIs - SLS Index Configuration Manager
This document is the API / CLI reference for the index management skill. It covers the four index-management endpoints: GetIndex, CreateIndex, UpdateIndex, and DeleteIndex.
Command List
| CLI Command | API Action | Operation Type | Description | Documentation |
|---|---|---|---|---|
aliyun sls get-index | GetIndex | read | Read the current index configuration of a Logstore | Doc |
aliyun sls create-index | CreateIndex | write | Create the initial index configuration for a Logstore | Doc |
aliyun sls update-index | UpdateIndex | write (overwrite) | Replace the entire index configuration of a Logstore | Doc |
aliyun sls delete-index | DeleteIndex | write (destructive) | Remove the entire index configuration of a Logstore | Doc |
---
CLI Conventions
- Always use the product namespace
aliyun slsand kebab-case subcommands / flags. - Do not use PascalCase OpenAPI action names (
UpdateIndex) as CLI subcommands. - Do not pass a JSON
--paramsblob. The SLS plugin exposes request fields as individual flags. - For object-valued index parameters, write compact JSON to files and pass them with
$(cat ...), for example--line "$(cat /tmp/sls-index-line.json)"and--keys "$(cat /tmp/sls-index-keys.json)". - Pass scalar body properties directly, for example
--max-text-len 2048,--scan-index true, or--log-reduce false.
---
Index Configuration Schema
The same JSON object is shared by CreateIndex, UpdateIndex, and the response of GetIndex.
| Field | Type | Required | Description |
|---|---|---|---|
line | object | conditional | Full-text index. At least one of line / keys / scan_index must be present. |
line.token | string[] | yes (if line present) | Tokenizer delimiters, e.g. [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", ":", "\n", "\t", "\r"]. |
line.caseSensitive | boolean | no | Default false. |
line.chn | boolean | no | Enable Chinese tokenization. Default false. Enabling reduces write throughput. |
line.include_keys | string[] | no | Restrict full-text index to these fields. Mutually exclusive with exclude_keys. |
line.exclude_keys | string[] | no | Exclude these fields from full-text index. Mutually exclusive with include_keys. |
keys | object | conditional | Field index map: { <fieldName>: <IndexKey> }. At least one of line / keys / scan_index must be present. |
scan_index | boolean | no | Enable scan index. Default false. At least one of line / keys / scan_index must be present. |
max_text_len | integer | no | Max bytes per analyzed text value, range 64–16384, default 2048. |
log_reduce | boolean | no | Enable log clustering (LogReduce). Default false. |
log_reduce_white_list | string[] | no | Field whitelist for clustering. Effective only when log_reduce: true. |
log_reduce_black_list | string[] | no | Field blacklist for clustering. Effective only when log_reduce: true. |
ttl | integer | response-only | Index lifetime in days. Read via GetIndex. |
index_mode | string | response-only | Index version, typically v2. Read via GetIndex. |
lastModifyTime | integer | response-only | Last modification time in Unix seconds. Read via GetIndex. |
storage | string | response-only | Storage type, fixed to pg. Read via GetIndex. |
IndexKey (entry value of keys)
| Field | Type | Required | Description |
|---|---|---|---|
type | string | yes | One of text / long / double / json. |
doc_value | boolean | no | true enables SQL analytics (SELECT, GROUP BY, WHERE) on this field. Required for SQL. |
alias | string | no | Field alias, optional. |
caseSensitive | boolean | no | For text / json. Default false. |
chn | boolean | no | For text / json. Default false. Enable only when content contains Chinese. |
token | string[] | no | Tokenizer delimiters for text / json. |
index_all | boolean | no | For json. Auto-index all leaf text fields under the JSON. |
max_depth | integer | no | For json. Max recursion depth. |
json_keys | object | no | For json. Per-leaf overrides: { <jsonPath>: <IndexJsonKey> }. |
IndexJsonKey (entry value of json_keys)
| Field | Type | Required | Description |
|---|---|---|---|
type | string | yes | text / long / double. |
doc_value | boolean | no | Enable analytics on this leaf. |
alias | string | no | Leaf alias. |
caseSensitive | boolean | no | For text. |
chn | boolean | no | For text. |
IndexJsonKey does not support its own token; text leaves use the parent json field's tokenizer.
Minimum example — full-text only
{
"line": {
"chn": false,
"caseSensitive": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
}
}Mixed example — full-text + field index
{
"line": {
"chn": false,
"caseSensitive": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", "?", "&", "/", ":", "\n", "\t", "\r"]
},
"keys": {
"status": { "type": "long", "doc_value": true },
"request_time": { "type": "double", "doc_value": true },
"request_uri": {
"type": "text",
"doc_value": true,
"caseSensitive": false,
"chn": false,
"token": [",", " ", ";", "=", "(", ")", "[", "]", "{", "}", ":", "/", "\n", "\t", "\r"]
},
"extra": {
"type": "json",
"doc_value": true,
"index_all": true,
"max_depth": 4
}
},
"max_text_len": 2048
}---
GetIndex
GET /logstores/{logstore}/index — invoke via aliyun sls get-index.
Input — Required
| Parameter | Type | CLI Flag | Description |
|---|---|---|---|
| Project | string | --project | Project name. |
| Logstore | string | --logstore | Logstore name. |
Output
The full index configuration object (see schema above) plus response-only fields ttl, index_mode, lastModifyTime, storage.
Common Errors
| HTTP Status | ErrorCode | Meaning |
|---|---|---|
| 404 | ProjectNotExist | Project name is wrong or in a different region. |
| 404 | LogStoreNotExist | Logstore name is wrong. |
| 404 | IndexConfigNotExist | The Logstore has no index configured — proceed to CreateIndex. |
---
CreateIndex
POST /logstores/{logstore}/index — invoke via aliyun sls create-index.
Input — Required
| Parameter | Type | CLI Flag | Description |
|---|---|---|---|
| Project | string | --project | Project name. |
| Logstore | string | --logstore | Logstore name. |
Input — Optional (effectively required: at least one of line / keys / scan_index must be present in the body)
| Parameter | Type | CLI Flag | Description |
|---|---|---|---|
| line | object | --line | Full-text index config. JSON. |
| keys | object | --keys | Field index map. JSON. |
| scan_index | boolean | --scan-index | Enable scan index. |
| max_text_len | integer | --max-text-len | Max bytes per analyzed text value. |
| log_reduce | boolean | --log-reduce | Enable LogReduce clustering. |
| log_reduce_white_list | string[] | --log-reduce-white-list | Whitelist for LogReduce. |
| log_reduce_black_list | string[] | --log-reduce-black-list | Blacklist for LogReduce. |
Common Errors
| HTTP Status | ErrorCode | Meaning |
|---|---|---|
| 400 | IndexInfoInvalid | Body missing required fields (e.g. token for line) or malformed JSON. |
| 400 | IndexAlreadyExist | The Logstore already has an index — use UpdateIndex instead. |
| 404 | ProjectNotExist | Project name is wrong or region mismatch. |
| 404 | LogStoreNotExist | Logstore name is wrong. |
---
UpdateIndex
PUT /logstores/{logstore}/index — invoke via aliyun sls update-index.
Input — Required
Same as CreateIndex.
Body Semantics — Replace Full Config
The request body replaces the entire index configuration. Any field not included in the body is dropped. Treat update-index like create-index against an existing Logstore: prepare the complete final config, then submit it.
Call get-index first when you need a backup or a reference for the existing config.
Common Errors
Same set as CreateIndex, plus:
| HTTP Status | ErrorCode | Meaning |
|---|---|---|
| 404 | IndexConfigNotExist | The Logstore has no index yet — call CreateIndex instead. |
---
DeleteIndex
DELETE /logstores/{logstore}/index — invoke via aliyun sls delete-index.
Input — Required
| Parameter | Type | CLI Flag | Description |
|---|---|---|---|
| Project | string | --project | Project name. |
| Logstore | string | --logstore | Logstore name. |
Effect & Risk
- Removes all field indexes and full-text indexes; query / SQL / SPL on this Logstore will stop working.
- The deletion takes effect within ~1 minute; in-flight queries may continue to succeed during the propagation window.
- Always confirm with the user before invoking. This skill never chains
delete-indexafter another write.
Common Errors
| HTTP Status | ErrorCode | Meaning |
|---|---|---|
| 404 | ProjectNotExist | Project name is wrong or region mismatch. |
| 404 | LogStoreNotExist | Logstore name is wrong. |
Reference Documentation
| Document | Description |
|---|---|
| GetIndex API | Official API reference |
| CreateIndex API | Official API reference |
| UpdateIndex API | Official API reference |
| DeleteIndex API | Official API reference |
| Index configuration overview | Concepts: full-text, field index, tokenization, doc_value |
| Aliyun CLI — SLS plugin | CLI source and release notes |