1. Delete by IDs
1.1. Parameter 3
1.1.1. Request parameters
Parameter | Type | Required | Description |
serviceId | Long | Yes | The service ID. |
ids | List | Yes | The primary key IDs of the data to delete. |
{
"serviceId": 1,
"ids": [1]
}1.1.2. Response parameters
Parameter | Parameter Type | Description | ||
code | Integer | The error code. | ||
success | Boolean | Indicates whether the call was successful. | ||
requestId | String | The request ID. | ||
data | Object | The response content. | ||
msg | String | The response message. | ||
{
"code":200,
"data": null,
"msg": null,
"requestId":"326F95A0-720A-5293-BDA7-4B91B09E636B",
"success":true
}1.2. SDK calls
1.2.1. Java SDK
1.2.1.1. Maven dependency
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alinlp20200629</artifactId>
<version>2.2.0</version>
</dependency>1.2.1.2. Call example
/**
* Initialize the client using an AccessKey ID and AccessKey secret.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// Required. Your AccessKey ID.
.setAccessKeyId(accessKeyId)
// Required. Your AccessKey secret.
.setAccessKeySecret(accessKeySecret);
// For the endpoint, see https://api.aliyun.com/product/alinlp
config.endpoint = "alinlp.cn-beijing.aliyuncs.com";
return new Client(config);
}
public static void main(String[] args_) throws Exception {
DeleteServiceDataByIds();
}
public static void DeleteServiceDataByIds() throws Exception {
// Hard-coding an AccessKey pair in your code can lead to a leak, which compromises the security of all resources in your account. The following code is for reference only. We recommend using a more secure method, such as Security Token Service (STS). For more information about authentication methods, see: https://help.aliyun.com/document_detail/378657.html
Client client = createClient(AccessConstant.AK3, AccessConstant.SK3);
DeleteServiceDataByIdsRequest requset = new DeleteServiceDataByIdsRequest()
.setServiceId(1L).setIds(Arrays.asList("1"));
try {
DeleteServiceDataByIdsResponse response = client.deleteServiceDataByIds(requset);
System.out.println(JSON.toJSONString(response.getBody(), SerializerFeature.PrettyFormat));
} catch (Exception e) {
e.printStackTrace();
}
}1.2.2. Python SDK
1.2.2.1. Pip source
pip install aliyun-python-sdk-alinlp==1.0.23
pip install aliyun-python-sdk-core1.2.2.2. Call example
from aliyunsdkalinlp.request.v20200629 import DeleteServiceDataByIdsRequest
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.auth.credentials import AccessKeyCredential
import os
os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'] = 'xxxx'
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'] = 'xxxx'
def delete_service_data():
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)
request = DeleteServiceDataByIdsRequest.DeleteServiceDataByIdsRequest()
request.set_ServiceId(1)
request.set_Ids([1])
request.set_accept_format('json')
response = client.do_action_with_exception(request)
# For Python 2: print(response)
print(str(response, encoding='utf-8'))
if __name__ == '__main__':
delete_service_data()
2. Delete by conditions
2.1. Parameters
2.1.1. Request parameters
Parameter | Type | Required | Description |
serviceId | Long | Yes | The service ID. |
conditions | Object | Yes | The deletion conditions. This is equivalent to the body of an Elasticsearch (ES) delete API call and must follow the ES parameter format. |
{
"serviceId": 1,
"conditions": {
"query": {
"term": {
"id": 1
}
}
}
}2.1.2. Response parameters
Parameter | Type | Description | ||
code | Integer | The error code. | ||
success | Boolean | Indicates whether the call was successful. | ||
requestId | String | The request ID. | ||
data | Object | The response content. | ||
msg | String | The response message. | ||
{
"code":200,
"data": null,
"msg": null,
"requestId":"326F95A0-720A-5293-BDA7-4B91B09E636B",
"success":true
}2.2. SDK calls
2.2.1. Java SDK
2.2.1.1. Maven dependencies
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alinlp20200629</artifactId>
<version>2.2.0</version>
</dependency>2.2.1.2. Call example
/**
* Initialize the client using an AccessKey ID and AccessKey secret.
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// Required. Your AccessKey ID.
.setAccessKeyId(accessKeyId)
// Required. Your AccessKey secret.
.setAccessKeySecret(accessKeySecret);
// For the endpoint, see https://api.aliyun.com/product/alinlp
config.endpoint = "alinlp.cn-beijing.aliyuncs.com";
return new Client(config);
}
public static void main(String[] args_) throws Exception {
DeleteServiceDataByConditions();
}
public static void DeleteServiceDataByConditions() throws Exception {
// Hard-coding an AccessKey pair in your code can lead to a leak, which compromises the security of all resources in your account. The following code is for reference only. We recommend using a more secure method, such as Security Token Service (STS). For more information about authentication methods, see: https://help.aliyun.com/document_detail/378657.html
Client client = createClient(AccessConstant.AK3, AccessConstant.SK3);
Map<String, JSONObject> conditions = new HashMap<>();
conditions.put("query", JSON.parseObject("{\"term\":{\"id\":1}}"));
DeleteServiceDataByConditionsRequest requset = new DeleteServiceDataByConditionsRequest()
.setServiceId(1L).setConditions(conditions);
try {
DeleteServiceDataByConditionsResponse response = client.deleteServiceDataByConditions(requset);
System.out.println(JSON.toJSONString(response.getBody(), SerializerFeature.PrettyFormat));
} catch (Exception e) {
e.printStackTrace();
}
}2.2.2. Python SDK
2.2.2.1. Pip source
pip install aliyun-python-sdk-alinlp==1.0.23
pip install aliyun-python-sdk-core2.2.2.2. Call example
from aliyunsdkalinlp.request.v20200629 import DeleteServiceDataByConditionsRequest
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.auth.credentials import AccessKeyCredential
import os
os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'] = 'xxxx'
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'] = 'xxxx'
def delete_service_data():
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)
request = DeleteServiceDataByConditionsRequest.DeleteServiceDataByConditionsRequest()
request.set_ServiceId(1)
request.set_Conditions(json.loads("{\"serviceId\":1,\"conditions\":{\"query\":{\"term\":{\"id\":1}}}}"))
request.set_accept_format('json')
response = client.do_action_with_exception(request)
# For Python 2: print(response)
print(str(response, encoding='utf-8'))
if __name__ == '__main__':
delete_service_data()
该文章对您有帮助吗?