All Products
Search
Document Center

OpenSearch:Update data

Last Updated:Oct 19, 2026

This topic describes the structure for updating data (add and delete).

URL

/update/$table_name/actions/bulk

  • $table_name is in the instanceID_tableName format. For example, if the instance ID is ha-843qfng6ydhb and the table name is test, then table_name is ha-843qfng6ydhb_test.

  • The preceding URL omits factors such as request header parameters and encoding.

  • The preceding URL omits the host address used to access the application.

Supported formats

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 which data is pushed. Example: id

host

string

The request host. You can view it on the instance details page under API Endpoint > API Domain Name. For the Internet, you can view it on the instance details page under Network Information > Public Domain Name. Example: ha-cn-**********.ha.aliyuncs.com

Signature mechanism

You can use the following method to calculate the signature (authorization)

Parameter

Type

Description

accessUserName

string

The username. You can view it on the instance details page under Network Information.

accessPassWord

string

The password. You can modify it on the instance details page under 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);
		}
}

Format of a correctly returned authorization value

cm9vdDp******mdhbA==

Note: When you set the authorization parameter in an HTTP request, you must 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. Defines the operation to perform on the document. Valid values: "add" and "delete". We recommend that you perform batch update operations in a single request to improve network interaction and processing efficiency. "add" adds a document. If a document with the same primary key already exists, the system performs a "delete" operation followed by an "add" operation. "delete" deletes a document. If no document with the specified primary key exists, the deletion is considered successful.

  • fields: Required. The content of the document to operate on. The primary key field is required because all system operations are performed based on the primary key. For "delete", you need to provide only the primary key of the document.

  • For the Array type, use a JsonArray, for example, [{“fields”: { “id”: “0”,”int_array”: [14,85],”string_array”: [“abc”,”xyz”]},”cmd”: “add”}].

  • Note: The outermost layer is of the JsonArray type, which supports batch operations on multiple documents.

Example

Request: (Request header parameters and encoding are omitted here.)

http://ha-cn-**********.ha.aliyuncs.com/update/$table_name/actions/bulk

//The following data to be uploaded must be placed in the request body
[{
	"cmd": "add",
	"fields": {
		"id": 1,
		"name": "Test Data Push"
	}
}]

Successful response

If no parameters are returned, the data is pushed successfully.

Error response

[
    {
        "code": 3012,
        "message": "Resource not found."
    }
]

Usage notes

  • When you push data by using the API or SDK, the field names of the application are case-insensitive.

  • Pushing data by using the API or SDK is subject to limits on the number of pushes and the data size. The limits vary based on the application. For more information, see the description of system limits.

  • After you upload data, make sure to check the return value and retry for the relevant error codes (especially error 3007). Otherwise, data loss may occur. In addition, data processing is asynchronous. A return value of "OK" indicates only that the system has received the data successfully. Errors that occur during data processing are displayed in the error information in the console. Check them in a timely manner.

  • The size of POST data is limited. If the total size of the documents that you upload is too large (2 MB before encoding), the server rejects all parameters and returns an exception.