1. Parameters
1.1. Request parameters
Parameter Name | Type | Required | Description |
action | String | Yes | The name of the API. To be determined. |
serviceId | Long | Yes | The service ID. |
conditions | Object | Yes | The update conditions. This is equivalent to the body of an Elasticsearch update API call and must conform to the Elasticsearch parameter format. |
{
"serviceId": 1,
"conditions": {
"query": {
"term": {
"id": 1
}
},
"script": {
"source": "ctx._source.content = 'Test content 1-modified 1'"
}
}
}1.2. Response parameters
Parameter | Type | Description | ||
code | Integer | The error code. | ||
success | Boolean | Indicates whether the request was successful. | ||
requestId | String | The request ID. | ||
msg | String | The response message. | ||
data | Object | The response content. | ||
{
"code": 200,
"data": null,
"success": true,
"msg": null,
"requestId": "4117446A-308C-4CA6-B265-39F4A96C30B5"
}2. SDK calls
2.1. Java SDK
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>2.1.2. Call example
/**
* Initializes the client with 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 {
UpdateServiceData();
}
public static void UpdateServiceData() throws Exception {
// Leaking your AccessKey in the project code may compromise the security of all resources in your account. The following code is for reference only. Use a more secure method, such as Security Token Service (STS), for authentication. 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}}"));
conditions.put("script", JSON.parseObject("{\"source\":\"ctx._source.content = 'Test content 1-modified 2'\"}"));
UpdateServiceDataRequest requset = new UpdateServiceDataRequest()
.setServiceId(1L).setConditions(conditions);
try {
UpdateServiceDataResponse response = client.updateServiceData(requset);
System.out.println(JSON.toJSONString(response.getBody(), SerializerFeature.PrettyFormat));
} catch (Exception e) {
e.printStackTrace();
}
}2.2. Python SDK
2.2.1. pip source
pip install aliyun-python-sdk-alinlp==1.0.23
pip install aliyun-python-sdk-core2.2.2. Call example
from aliyunsdkalinlp.request.v20200629 import UpdateServiceDataRequest
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 update_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 = UpdateServiceDataRequest.UpdateServiceDataRequest()
request.set_service_id(1)
request.set_conditions(json.loads("{\"serviceId\":1,\"conditions\":{\"query\":{\"term\":{\"id\":1}},\"script\":{\"source\":\"ctx._source.content = 'Test content 1-modified 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__':
update_service_data()
该文章对您有帮助吗?