Create indexes on a Simple Log Service Logstore to enable log query and analysis. This topic covers index types, configuration, and billing.
Why indexes are required
Keywords retrieve content from raw logs. For example, a log entry curl/7.74.0 contains the keyword curl, but without parsing, the entry is a single unit that does not match curl exactly. Simple Log Service cannot retrieve it.
To make logs searchable, split them into terms with delimiters. For example, applying \n\t\r,;[]{}()&^*#@~=<>/\?:'" produces the terms curl and 7.74.0. Simple Log Service builds an index from these terms. Logs can be queried and analyzed only after an index is created.
Simple Log Service supports both a full-text index and a field index. If you configure both for the same Logstore, the field index configuration takes precedence.
Index types
Full-text index
A full-text index splits an entire log entry into text-type terms by Delimiter. You can then query logs by keyword. For example, Chrome or Safari finds logs containing Chrome or Safari.
-
The Delimiter does not support Chinese characters. To handle Chinese text, enable Include Chinese. SLS then automatically tokenizes Chinese content based on grammar.
-
If you configure only a full-text index, you can use full-text search syntax. Query syntax and functions
Field index
A field index splits logs by field name (KEY) and tokenizes each field's content. Four data types are supported: text, long, double, and JSON. Query by field name and value (Key:Value) or with a SELECT statement. Query syntax and features
-
To query or analyze a specific field with a SELECT statement, you must create a field index for it. A field index takes precedence over a full-text index when both are configured for the same field.
-
text fields support full-text queries, field-specific queries, and analytic statements (SELECT).
-
Without a full-text index, a full-text query searches only across all text-type fields.
-
With a full-text index enabled, full-text queries search all logs.
-
-
long and double fields support field-specific queries and analytic statements (SELECT).
Create an index
-
Index configurations directly affect query and analysis results. New indexes take about one minute to take effect.
-
Indexes apply only to newly ingested data. To query historical data, reindex it.
-
SLS automatically creates indexes for some reserved fields.
The delimiters for
__topic__and__source__are empty, so queries on these fields must use exact match. -
Fields prefixed with
__tag__do not support full-text indexing. Create a text-type field index to query and analyze them, for example:*| select "__tag__:__receive_time__". -
If a log contains duplicate field names (for example,
request_time), the console displays one asrequest_time_0. The underlying name remainsrequest_time. Always use the original name when creating indexes, querying, analyzing, shipping, or transforming data.
Console
API
SDK
CLI
Update an index
Procedure
Disable an index
After you Disable an index, SLS automatically releases the storage for historical index data when the Logstore's retention period expires.
Procedure
Index configuration examples
Example 1
The log content contains the request_time field. You can execute the query request_time>100.
-
With only a full-text index, the search returns logs that contain the three terms
request_time,>(not a delimiter), and100. -
With field indexes of the double and long types, the query returns logs where
request_timeis greater than 100. -
If you create a full-text index and field indexes for the double and long types, the full-text index for
request_timeis ignored, and the query returns logs whererequest_timeis greater than 100.
Example 2
Because the log content contains the request_time field, you can run the full-text query request_time.
-
If you create only a field index of the
doubleorlongdata type, no relevant logs are returned. -
You can create only a full-text index to query for logs that contain
request_timefrom all log text. -
Query for logs that contain
request_timefrom fields that have a field index of thetexttype.
Example 3
The log content contains the status field. Run the analysis statement * | SELECT status, count(*) AS PV GROUP BY status.
-
If you create only a full-text index, no relevant logs are returned.
-
Creating a field index for
statusreturns the different status codes and their corresponding total PVs.
Index traffic
Full-text index
All field names and values count toward index traffic.
Field index
Index traffic calculation varies by field data type:
-
text type: Both the field name and value count toward
index traffic. -
long and double types: The field name does not count toward
index traffic. Each field value contributes a fixed 8 bytes.For example, if an index is created on the
statusfield (long type) with value200, the stringstatusis not counted. The index traffic for200is a fixed 8 bytes. -
JSON type: Both field names and values count toward
index traffic, including sub-keys not explicitly indexed. How is the index traffic of JSON fields calculated?-
Non-indexed sub-keys:
index trafficis calculated as text type. -
Indexed sub-keys:
index trafficis calculated based on the specified data type (text, long, or double).
-
Billing
Logstores in pay-by-ingested-data mode
-
Indexes occupy storage space. Manage intelligent tiered storage
-
Reindexing does not incur fees.
-
Index trafficcharges: Billable items for the pay-by-ingested-data mode
Logstores in pay-by-feature mode
-
Indexes occupy storage space. Manage intelligent tiered storage
-
Creating an index generates billable
index traffic. Billable items for the pay-by-feature mode How do I reduce index traffic fees? -
Reindexing incurs fees. Billable items and prices are the same as for creating an index.
Next steps
-
Query and analysis examples:







