Data processing
Add, delete, and perform batch operations on data.
URL
/update/$table_name/actions/bulk
$table_name is the name of the data source.
The URL above does not include request header parameters or encoding details.
The URL above does not include the host address of the application.
Supported format
JSON
HTTP request method
POST
Header parameters
Parameter | Type | Description |
authorization | string | The signature. |
X-Opensearch-Swift-PK-Field | string | The primary key of the index table to push. Example: id. |
host | string | The request host. To view the host, go to the instance details page and find API Endpoint > API Domain Name. Example: ha-cn-**********.ha.aliyuncs.com. |
Signature mechanism
Calculate the signature (authorization) using the following method.
Parameter | Type | Description |
accessUserName | string | The username. To view the username, go to the instance details page and find Network Information. |
accessPassWord | string | The password. To change the password, go to the instance details page and find Network Information. |
import com.aliyun.darabonba.encode.Encoder;
import com.aliyun.darabonbastring.Client;
public class GenerateAuthorization {
public static void main(String[] args) throws Exception {
String accessUserName = "username";
String accessPassWord = "password";
String realmStr = "" + accessUserName + ":" + accessPassWord + "";
String authorization = Encoder.base64EncodeToString(Client.toBytes(realmStr, "UTF-8"));
System.out.println(authorization);
}
}The correct format for the authorization value is as follows:
cm9vdDp******mdhbA==Note: When you set the `authorization` parameter in an HTTP request, add the `Basic` prefix.
Example:
authorization: Basic cm9vdDp******mdhbA==Document data format (body)
[
{
"cmd": "add",
"fields": {
"id": "1",
"title": "This is the title",
"body": "This is the body"
}
},
{
"cmd": "delete",
"fields": {
"id": "3"
}
}
]cmd: Required. This parameter specifies the operation to perform on the document. Valid values are `add` and `delete`. The Standard Edition does not support the `update` operation. To improve network and processing efficiency, you can perform batch operations in a single request. `add`: Adds a document. If a document with the same primary key already exists, the system deletes the existing document before it adds the new one. `delete`: Deletes a document. If a document with the specified primary key does not exist, the operation is still considered successful.
fields: Required. This parameter specifies the content of the document. The primary key field is required because the system uses the primary key for all operations. For a `delete` operation, you only need to specify the primary key of the document.
For fields of the Array type, use a JsonArray. For example: [{“fields”: { “id”: “0”,”int_array”: [14,85],”string_array”: [“abc”,”xyz”]},”cmd”: “add”}].
Note: The top-level element is a JsonArray, which lets you perform batch operations on multiple documents.
Example
Request (This example does not include request header parameters or encoding details):
http://ha-cn-**********.ha.aliyuncs.com/update/$table_name/actions/bulk
// Place the following data in the request body
[{
"cmd": "add",
"fields": {
"id": 1,
"name": "Test Data Push"
}
}]Successful response
An empty response indicates that the data push was successful.
Error response
[
{
"code": 3012,
"message": "Resource not found."
}
]Notes
When you push data using an API or SDK, the field names in the application are not case-sensitive.
Data pushes that use an API or SDK are subject to frequency and size limits. These limits vary based on the application. For more information, see the system limits documentation.
After you upload data, check the return value. You must retry the operation if you receive certain error codes, such as 3007. If you do not retry the operation, data loss may occur. Data processing is asynchronous. A return value of `OK` indicates only that the system has successfully received the data. Errors that occur during data processing are displayed in the console. You must promptly check the console for error messages.
The size of POST data is limited. If the total size of the documents that you upload exceeds 2 MB before encoding, the server rejects the request and returns an exception.