To effectively query and analyze logs collected in a Logstore, you must create indexes. This topic explains the concepts of Simple Log Service indexes, including index types, creation methods, disabling, configuration examples, and billing information.
Why you need to create indexes
Keywords are typically used to retrieve specific content from raw logs, such as entries containing curl
: curl/7.74.0
. Without splitting, the log text is treated as a single entity and cannot fully match the keyword curl
, making it non-retrievable by Simple Log Service.
For efficient retrieval, logs must be split into searchable words. Logs are divided using delimiters, which determine the split points. For instance, with delimiters such as \n\t\r,;[]{}()&^*#@~=<>/\?:'"
, the log splits into words like curl
and 7.74.0
. Simple Log Service then creates indexes based on these words, enabling log queries and analyses.
Simple Log Service projects support the creation of both full-text and field indexes. If both are created, field index configurations take priority.
Index types
Full-text indexes
Full-text indexes divide the entire log into text type words using Delimiters. Once full-text indexes are in place, you can perform keyword-based log queries. For instance, the query Chrome or Safari
retrieves logs containing either Chrome
or Safari
.
-
Delimiters are not compatible with Chinese characters. Enabling the Include Chinese option allows Simple Log Service to automatically segment Chinese text according to the rules of Chinese grammar.
-
If only full-text indexes are set up, you can use only full-text query capabilities. For more details, see Query syntax and features.
Field indexes
Field indexes categorize logs by field names (KEY) and then segment the content within fields using delimiters. They support four data types: text, long, double, and JSON. For more information, see Data types. After setting up field indexes, you can specify field names and values (Key:Value
) for log queries or use SELECT statements. For more details, see Field queries.
-
To query or analyze fields using SELECT statements, you must create field indexes. They take precedence over full-text indexes. If both are created, field index settings take priority.
-
Fields of the text type can be queried using full-text, field, and analytic (SELECT) query statements.
-
Without full-text indexes, full-text query statements return results from all text type fields.
-
With full-text indexes, full-text query statements return results from all logs.
-
-
Fields of the long and double types can be queried and analyzed using field and analytic (SELECT) query statements.
Create indexes
-
Different index configurations yield varying query and analysis outcomes. Set up indexes according to your business needs. Indexes typically take effect within one minute of creation.
-
Indexes are applicable only to new logs. To query historical logs, use the Reindex feature.
-
Simple Log Service automatically indexes certain reserved fields. For more information, see Reserved fields.
The delimiters for the
__topic__
and__source__
indexes are empty. Exact keyword matches are required when querying these fields. -
Fields prefixed with
__tag__
do not support full-text indexing. Before querying or analyzing such fields, you must create field indexes, for example,*| select "__tag__:__receive_time__"
. -
If a log contains duplicate field names (e.g., both named request_time), Simple Log Service displays one as request_time_0. The original field name request_time is still used in storage, so use the original name when creating indexes, querying, analyzing, shipping, or transforming logs.
Console method
API methods
SDK method
CLI method
Disable indexes
After Disabling Indexes, the storage space used by historical indexes will be automatically cleared once the data retention period for the associated Logstore ends.
Procedure
Index configuration examples
Example 1
The log content includes a request_time
field. To query this field, execute the statement request_time>100
.
Configuring only full-text indexes will return logs containing the terms
request_time
,>
, and100
.Configuring only field indexes for double and long types will return logs where
request_time
exceeds 100.Configuring both full-text and field indexes for double and long types will invalidate the full-text index for
request_time
, returning logs whererequest_time
exceeds 100.
Example 2
The log content includes a request_time
field. To perform a full-text query, use the statement request_time
.
Configuring only field indexes for double and long types will not return any related logs.
Configuring only full-text indexes will query logs containing
request_time
from all log texts.Configuring only field indexes for the text type will query logs containing
request_time
from fields indexed as text.
Example 3
The log content includes a status
field. To analyze this field, execute the statement * | SELECT status, count(*) AS PV GROUP BY status
.
Configuring only full-text indexes will not return any related logs.
Configuring a field index for
status
will yield the different status codes and their corresponding total page views (PVs).
Index traffic descriptions
Full-text index
In a full-text index, both field names and field values are stored as text and are included in the index traffic.
Field index
Index traffic calculation depends on the data type of the field.
-
Text type: Index traffic includes both field names and field values.
-
The Long and double data types: Field names do not contribute to index traffic. Index traffic is consistently 8 bytes for each field value.
For instance, when an index is created for the
status
field (long type), if the field value is200
, the termstatus
does not contribute to the index size, whereas the index size for the value200
is consistently 8 bytes. -
JSON type: Index traffic encompasses both field names and field values, including child nodes not indexed. For more information, see calculating index traffic for JSON type fields.
-
Child nodes without indexes are treated as text type for index traffic calculation.
-
Child nodes with indexes have their index traffic calculated according to their data type, whether text, long, or double.
-
Billing instructions
Logstore billed by data write volume
-
Indexes created will occupy storage space. For information on storage classes, see Manage Intelligent Storage Tiering.
-
Reindexing is not subject to fees.
-
For details on billing for index traffic, refer to Billable Items for Data Write Volume Billing Mode.
Logstore billed by feature usage
-
Indexes created will occupy storage space. For information on storage classes, see Manage Intelligent Storage Tiering.
-
Creating indexes incurs traffic costs. For index traffic billing details, refer to Billable Items for Feature Usage Billing Mode under Index Traffic - Log Index and Index Traffic - Log Index - Query Type. For tips on reducing index traffic costs, see How to Reduce Index Traffic Fees?.
-
Reindexing incurs fees, with billable items and rates identical to those for creating indexes.
What to do next
-
For examples of search and analysis, refer to:
-
For guidance on query optimization techniques, see Methods to Improve Log Query and Analysis Speed.
-
For details on querying and analyzing JSON-type website logs, see Search and Analyze JSON Logs.