Bulk

Batch document operation

/ Bulk, / Index

Batch document operation #

Provides a efficient way to perform multiple index, create, delete, and update operations in a single request.

Examples #

POST /_bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

The API returns the following result:

{
  "took": 30,
  "errors": false,
  "items": [
    {
      "index": {
        "_collection": "default:test",
        "_id": "0,0",
        "result": "created",
        ...
      }
    },
    {
      "delete": {
        "_collection": "default:test",
        "_id": "0,1",
        "result": "not_found",
        ...
      }
    },
    {
      "create": {
        "_collection": "default:test",
        "_id": "0,2",
        "result": "created",
        ...
      }
    },
    {
      "update": {
        "_collection": "default:test",
        "_id": "0,0",
        "result": "updated",
        ...
      }
    }
  ]
}

Request #

POST /_bulk
POST /<target>/_bulk

Path parameters #

  • <target>
    (Optional, string) Name of the collection to target. Actions that don’t explicitly specify their target in the action line use it.

Query parameters #

  • realtime
    (Optional, boolean, default: true) Request-level write-mode switch that overrides schema property-level realtime settings for every document in this request: false applies the batch WAL-only (durable immediately, searchable after the offline epoch build).
  • key_as_id
    (Optional, boolean, default: false) compatibility rendering: keyed documents answer with the user key AS _id (see the index API).
  • sync_replication
    (Optional, boolean) Opt back into synchronous inline replication for this request (wait for the replica RPC and count it in the response).

Request body #

The actions are specified in the request body using a newline delimited JSON (NDJSON) structure:

...