Update a saved search

Updated at:

Call the UpdateSavedSearch operation to update a saved search.

Prerequisites

Parameters

def update_savedsearch(self, project, detail):

Request parameters

Parameter

Type

Required

Description

project

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.

detail

String

Yes

A JSON string that contains the saved search configuration. Example:

detail = {
    "filterjson": "{\"filterJson\":{\"children\":[]},\"filterQuery\":\"\"}",
    "logstore": "logstore-1",
    "savedsearchName": "savedsearch-1",
    "searchQuery": "* | SELECT status, count(*) AS PV GROUP BY status",
    "topic": ""
}

The detail parameter contains the following fields:

Parameter

Type

Required

Description

logstore

String

Yes

The name of the logstore. The logstore in Simple Log Service is used to collect, store, and query logs. See Manage Logstores.

savedsearchName

String

Yes

The name of the saved search. The name must be unique within a Simple Log Service project and 3 to 63 characters long. For more information, see Saved search.

searchQuery

String

Yes

The query statement or query and analysis statement. For more information, see Query and analysis overview.

topic

String

No

The topic of logs. The default value is an empty string. For more information, see Log topics.

Response parameters

For details about the response parameters, see UpdateSavedSearch.

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 = "proj-test-1"
detail = {
    "filterjson": "{\"filterJson\":{\"children\":[]},\"filterQuery\":\"\"}",
    "logstore": "logstore-1",
    "savedsearchName": "savedsearch-1",
    "searchQuery": "* | SELECT status, count(*) AS PV GROUP BY status",
    "topic": ""
}


def main():
    # Update a saved search.
    res = client.update_savedsearch(project, detail)
    res.log_print()


if __name__ == '__main__':
    main()

Sample response

header:  {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 15 Oct 2024 07:37:24 GMT', 'x-log-time': '1728977844', 'x-log-requestid': '670E1BB4C66130BE5DD0****'}

Process finished with exit code 0

References