The bulk API lets you add, update, or delete multiple documents in a single request. Batching operations reduces round trips and improves throughput — send multiple operations together whenever practical.
Prerequisites
Before you begin, ensure that you have:
An OpenSearch application
Credentials to sign API requests. For signing details, see Signature method of OpenSearch API V3
Upload documents
Endpoint
POST /v3/openapi/apps/<app_name>/<table_name>/actions/bulk| Placeholder | Description |
|---|---|
<app_name> | Name of your application |
<table_name> | Name of the table that receives the data |
The endpoint omits the host, request headers, and encoding details. For the full request format, see Signature method of OpenSearch API V3.
Request format: JSON
HTTP method: POST
Request body
The request body is a JSON array. Each element represents one document operation and contains the following fields.
cmd (required)
The operation to perform. Valid values: add, update, delete.
updateis not supported for standard applications. Useaddinstead.
add
Creates a document. If a document with the same primary key already exists, OpenSearch deletes the original before creating the new one.
{
"cmd": "add",
"fields": {
"id": "1",
"title": "This is the title",
"body": "This is the body"
}
}update
Updates the specified fields in an existing document. Only the fields you include in the request are modified.
{
"cmd": "update",
"fields": {
"id": "2",
"title": "This is the new title"
}
}delete
Deletes the document with the specified primary key. If no document with that primary key exists, the delete operation still executes.
{
"cmd": "delete",
"fields": {
"id": "3"
}
}fields (required)
The document fields to operate on. Always include the primary key field — OpenSearch uses it to identify the document.
For a delete operation, only the primary key field is required.
For fields of the ARRAY type, specify the value as a JSON array:
[
{
"cmd": "add",
"fields": {
"id": "0",
"int_array": [14, 85],
"string_array": ["abc", "xyz"]
}
}
]timestamp (optional, advanced applications only)
The time the operation was performed, in milliseconds. OpenSearch uses this to determine the order of operations on the same primary key.
If omitted, OpenSearch uses the time it receives the request.
Standard applications do not supporttimestamp. If you include it in a request to a standard application, OpenSearch returns error code4007.
Example request
The following example batches three operations — add, update, and delete — in a single request. All examples use the JSON array format at the outermost level.
POST http://<host>/v3/openapi/apps/app_schema_demo/tab/actions/bulkRequest body:
[
{
"cmd": "add",
"timestamp": 1401342874777,
"fields": {
"id": "1",
"title": "This is the title",
"body": "This is the body"
}
},
{
"cmd": "update",
"timestamp": 1401342874778,
"fields": {
"id": "2",
"title": "This is the new title"
}
},
{
"cmd": "delete",
"fields": {
"id": "3"
}
}
]Response
Check the status field first. If status is FAIL, inspect errors for details.
| Parameter | Type | Description |
|---|---|---|
status | STRING | OK if the request was received successfully; FAIL if the request failed |
result | STRING | true for successful requests; not returned for failed requests |
request_id | STRING | Unique request ID for troubleshooting |
errors | STRING | Error details. Each error includes: code (error code), message (error description), and params (additional parameters). See Error codes |
Success response
{
"errors": [],
"request_id": "150116724719940316170289",
"status": "OK",
"result": true
}Error response
{
"errors": [
{
"code": 2001,
"message": "The application to be managed does not exist. The application to be managed does not exist.",
"params": {
"friendly_message": "The application to be managed does not exist."
}
}
],
"request_id": "150116732819940316116461",
"status": "FAIL"
}Usage notes
Check the return value after every request. A
statusofOKmeans OpenSearch received the data — not that it was processed successfully. OpenSearch processes data asynchronously. If a processing error occurs, the error message appears in the OpenSearch console. Check the console regularly, and pay particular attention to error code3007.Request size limit: The request body must not exceed 2 MB before encoding. Requests that exceed this limit are rejected. You can push data for a limited number of times and of a limited size by calling API operations or using OpenSearch SDK. For push frequency and volume limits by application type, see Limits.
UTF-8 encoding for Chinese characters: If the request body contains Chinese characters, encode the body in UTF-8. The
Content-MD5header value must also be calculated from the UTF-8-encoded body.