Query index
Call the GetIndex operation to retrieve the index configuration of a specified 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 get_index_config(self, project_name, logstore_name):
Request parameters
|
Name |
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. |
Response parameters
For information about response parameters, see GetIndex - Obtain index.
Sample code
from aliyun.log import LogClient
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 Simple Log Service endpoint
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Create an instance of the LogClient class
client = LogClient(endpoint, access_key_id, access_key_secret)
project_name = "project-1"
logstore_name = "logstore-1"
def main():
# Obtain the index configuration information of the specified LogStore
res = client.get_index_config(project_name, logstore_name)
res.log_print()
if __name__ == '__main__':
main()
Sample response
GetLogStoreResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '341', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Sat, 12 Oct 2024 08:32:01 GMT', 'x-log-time': '1728721921', 'x-log-requestid': '670A34019D6586B41DD1****'}
index_configs: {'line': {'token': [',', '\t', '\n', ';'], 'caseSensitive': False, 'chn': False}, 'keys': {'key_1': {'type': 'text', 'token': [',', '\t', '\n', ';'], 'caseSensitive': False, 'doc_value': False}, 'key_2': {'type': 'text', 'token': [',', '\t', '\n', ';'], 'caseSensitive': False, 'doc_value': False}}}
Process finished with exit code 0
References
-
Index management APIs:
-
Alibaba Cloud Simple Log Service SDK for Python on GitHub provides additional sample code.