Update index
Call the UpdateIndex operation to update the index of a Logstore.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameter description
def update_index(self, project_name, logstore_name, index_detail):
Request parameters
|
Parameter |
Type |
Required |
Description |
|
project_name |
String |
Yes |
The name of the project. The project in Simple Log Service is used to isolate the resources of different users and control access to specific resources. See Manage projects. |
|
logstore_name |
String |
Yes |
The name of the logstore. The logstore in Simple Log Service is used to collect, store, and query logs. See Manage Logstores. |
|
index_detail |
IndexConfig |
Yes |
Index configuration. |
IndexConfig parameters
|
Name |
Type |
Required |
Description |
|
line_config |
IndexLineConfig |
Yes |
Configures the full-text index. |
|
key_config_list |
Dict[str, IndexLineConfig] |
Yes |
Field index configuration. Keys are field names (strings), values are IndexLineConfig objects. |
|
log_reduce |
bool |
No |
Enables LogReduce. When enabled, either the whitelist or blacklist takes effect, but not both.
|
IndexLineConfig parameters
|
Name |
Type |
Required |
Description |
|
token_list |
List |
Yes |
Delimiters used to split log content into tokens. For example, with delimiters |
|
case_sensitive |
bool |
No |
Enables case-sensitive matching.
|
|
chinese |
bool |
No |
Enables Chinese word segmentation. When enabled, shard read/write throughput decreases.
|
IndexKeyConfig parameters
|
Name |
Type |
Required |
Description |
|
index_type |
String |
No |
Index type. Default:
|
|
token_list |
List |
Yes |
Delimiters used to split log content into tokens. For example, with delimiters |
|
case_sensitive |
bool |
No |
Enables case-sensitive matching.
|
|
doc_value |
bool |
No |
Enables statistical analysis. When enabled, the field can be used in analytic statements. |
|
alias |
String |
No |
Alias of the index key. |
|
json_key_config |
IndexJsonKeyConfig |
No |
JSON subfield index configuration. Required when index_type is |
|
chinese |
bool |
No |
Enables Chinese word segmentation. When enabled, shard read/write throughput decreases.
|
IndexJsonKeyConfig parameters
|
Name |
Type |
Required |
Description |
|
index_all |
bool |
No |
When set to True, indexes all string values in JSON keys. |
|
max_depth |
int |
No |
When index_all is True, only JSON values with |
|
alias |
String |
No |
Alias of the index key. |
|
json_keys |
Dict[str, JsonKeyConfigValue] |
No |
Subfield index configuration for JSON fields. Add subfields by calling add_key on the IndexJsonKeyConfig instance. Example log field:
Set |
Response parameters
For response parameters, see: UpdateIndex - Update Index.
Sample code
from aliyun.log import LogClient, IndexConfig, IndexKeyConfig, IndexLineConfig
import os
# In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The endpoint of Simple Log Service.
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Instantiate the LogClient class.
client = LogClient(endpoint, access_key_id, access_key_secret)
project_name = "project-1"
logstore_name = "logstore-1"
def main():
ttl = 1
token_list = [",", "\t", "\n", ";"]
# Configure a full-text index.
line_config = IndexLineConfig(token_list, case_sensitive=False, include_keys=None, exclude_keys=None, chinese=None)
# Configure a field index.
index_config = IndexKeyConfig(token_list, case_sensitive=False, index_type='text', doc_value=False, alias=None,
json_key_config=None, chinese=None)
# Construct the index_detail configuration.
key_config_list = {"key_1": index_config, "key_2": index_config}
index_detail = IndexConfig(ttl, line_config, key_config_list, all_keys_config=None, log_reduce=None)
# Update the index configuration of the specified Logstore.
res = client.update_index(project_name, logstore_name, index_detail)
res.log_print()
if __name__ == '__main__':
main()
Sample response
UpdateIndexResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Sat, 12 Oct 2024 06:31:53 GMT', 'x-log-time': '1728714713', 'x-log-requestid': '670A17D9A94ADA57D6BB****'}
Process finished with exit code 0
References
-
Index management APIs:
-
Alibaba Cloud Simple Log Service SDK for Python on GitHub provides additional sample code.