This section uses the ListSearchLog operation as an example to demonstrate how to call Alibaba Cloud Elasticsearch APIs using developer tools such as the Alibaba Cloud Command-Line Interface (CLI), OpenAPI Explorer, and Alibaba Cloud SDKs.
Background information
When you call an API, refer to the API documentation for usage instructions and the required request parameters. If an error occurs after you send a request, check the API documentation for error code details.
Calling methods
Calling method | Scenarios | Limits |
Use this method if you frequently work with command-line tools. | Before using this method, ensure that you have installed the Alibaba Cloud CLI on your machine. For installation instructions on different operating systems, see: | |
Use this method if you prefer an interactive interface or are new to Alibaba Cloud products. | OpenAPI Explorer also lets you debug APIs and generate SDK request examples. For details, see OpenAPI Portal. | |
Use this method for SDK development or DevOps scenarios. | Using the Java SDK requires installing JDK (version 1.6 or later) and Maven in advance. |
Alibaba Cloud CLI example
Obtain the instance ID.
You can obtain the instance ID in one of the following two ways:
In the Kibana console, run the
GET /command. For more information, see Log on to the Kibana console.On your local machine, call the ListInstance operation.
aliyun elasticsearch ListInstance --zoneId cn-hangzhou
Call the ListSearchLog operation to retrieve system logs for the instance.
aliyun elasticsearch ListSearchLog --type INSTANCELOG --query level:warn --beginTime 1593332477000 --endTime 1593418877000 --page 1 --size 20 --InstanceId es-cn-n6w1o1x0w00******
OpenAPI Explorer example
Call the ListInstance operation to obtain the instance ID.
Call the ListSearchLog operation to query system logs for the instance.
If the query is successful, OpenAPI Explorer displays the log information.
Java SDK example
Create a Maven project.
Configure the POM dependencies.
<dependency> <groupId>com.aliyun</groupId> <artifactId>elasticsearch20170613</artifactId> <version>4.0.0</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.4.6</version> </dependency>ImportantSDK packages are updated frequently. We recommend downloading the latest version from Alibaba Cloud SDKs.
Create a Java program and call the ListSearchLog operation to query system logs for the instance.
import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonResponse; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.http.FormatType; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; public class ListSearchLog { public static void main(String[] args) { DefaultProfile profile = DefaultProfile.getProfile("<RegionId>", "<accessKeyId>", "<accessSecret>"); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); //request.setProtocol(ProtocolType.HTTPS); request.setMethod(MethodType.GET); request.setDomain("elasticsearch.<RegionId>.aliyuncs.com"); request.setVersion("2017-06-13"); request.setUriPattern("/openapi/instances/<instanceid>/search-log"); request.putQueryParameter("type", "INSTANCELOG"); request.putQueryParameter("query", "level:warn"); request.putQueryParameter("beginTime", "1593332477000"); request.putQueryParameter("endTime", "1593418877000"); request.putQueryParameter("page", "1"); request.putQueryParameter("size", "20"); request.putHeadParameter("Content-Type", "application/json"); String requestBody = "{}"; request.setHttpContent(requestBody.getBytes(), "utf-8", FormatType.JSON); try { CommonResponse response = client.getCommonResponse(request); System.out.println(response.getData()); } catch (ServerException e) { e.printStackTrace(); } catch (ClientException e) { e.printStackTrace(); } } }Parameter
Description
<RegionId>
The region where your Alibaba Cloud Elasticsearch instance resides. For valid values, see metric description.
<accessKeyId>
The AccessKey ID of your Alibaba Cloud account. For how to obtain it, see Obtain an AccessKey.
<accessSecret>
The AccessKey secret of your Alibaba Cloud account. For how to obtain it, see Obtain an AccessKey.
<instanceId>
The ID of your Alibaba Cloud Elasticsearch instance. For how to obtain it, see View basic instance information and ListInstance.
NoteFor more information about the query parameter (QueryParameter), see ListSearchLog.