Delete an index
Call the delete_index method of Simple Log Service SDK for Python to delete the index configuration of a Logstore. After deletion, new log data written to the Logstore is no longer indexed and cannot be queried or analyzed.
Prerequisites
-
Simple Log Service is activated.
-
Simple Log Service SDK for Python is initialized.
-
An index is created for the target Logstore. For more information, see Create an index.
Important: Deleting an index is irreversible. After you delete the index of a Logstore, the existing indexed data is no longer queryable. Proceed with caution.
Request parameters
The delete_index method uses the following syntax:
def delete_index(self, project_name, logstore_name)
| Parameter | Type | Required | Description |
|---|---|---|---|
project_name |
String | Yes | The name of the project. For more information, see Manage a project. |
logstore_name |
String | Yes | The name of the Logstore. For more information, see Manage a Logstore. |
Response parameters
Returns a DeleteIndexResponse object. For more information, see DeleteIndex - Delete an index.
Sample code
from aliyun.log import LogClient, LogException
import os
# Obtain the AccessKey ID and AccessKey secret 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', '')
# Specify the Simple Log Service endpoint.
# Replace with the endpoint for your region.
endpoint = "cn-hangzhou.log.aliyuncs.com"
# Create a LogClient instance.
client = LogClient(endpoint, access_key_id, access_key_secret)
# Specify the project and Logstore.
project_name = "your-project-name"
logstore_name = "your-logstore-name"
def main():
try:
# Delete the index of the specified Logstore.
response = client.delete_index(project_name, logstore_name)
response.log_print()
except LogException as e:
print(f"Failed to delete index. Error code: {e.get_error_code()}, "
f"Error message: {e.get_error_message()}, "
f"Request ID: {e.get_request_id()}")
if __name__ == '__main__':
main()
Sample response
A successful call returns a DeleteIndexResponse object:
DeleteIndexResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Sat, 12 Oct 2024 08:35:11 GMT', 'x-log-time': '1728722111', 'x-log-requestid': '670A34BF3A127CB513E4****'}
Process finished with exit code 0
Error codes
Common error codes for the delete_index method:
| HTTP status code | Error code | Error message | Description |
|---|---|---|---|
| 404 | ProjectNotExist | The Project does not exist : \{project_name\} | The specified project does not exist. |
| 404 | LogStoreNotExist | logstore \{logstore_name\} does not exist | The specified Logstore does not exist. |
| 400 | IndexConfigNotExist | The index configuration does not exist for this logstore. | The index configuration does not exist for the specified Logstore. |
| 500 | InternalServerError | Specified Server Error Message. | An internal server error occurred. Try again later. |
References
-
Index management supports the following API operations:
-
For more sample code, see Alibaba Cloud Simple Log Service SDK for Python on GitHub.