Bulk
> Documentation > Docs > INFINI Pizza > References > Document > Bulk

Bulk #

Provides a way to perform multiple index, create, delete, and update actions 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": {
        "_namespace": "default",
        "_collection": "test",
        "result": "created",
        ...
      }
    },
    {
      "delete": {
        "_namespace": "default",
        "_collection": "test",
        "result": "not_found",
        ...
      }
    },
    {
      "create": {
        "_namespace": "default",
        "_collection": "test",
        "result": "created",
        ...
      }
    },
    {
      "update": {
        "_namespace": "default",
        "_collection": "test",
        "result": "updated",
        ...
      }
    }
  ]
}

Request #

POST /_bulk
POST /<target>/_bulk

Path parameters #

  • <target>
    (Required, string) Name of the collection to target.

Request body #

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

action_and_meta_data\n
optional_source\n
action_and_meta_data\n
optional_source\n
....
action_and_meta_data\n
optional_source\n

The index and create actions expect a source on the next line, and have the same semantics as the standard API: create fails if a document with the same ID already exists in the target, index adds or replaces a document as necessary.

update expects that the partial doc, upsert, and script and its options are specified on the next line.

delete does not expect a source on the next line and has the same semantics as the standard delete API.

Because this format uses literal \n’s as delimiters, make sure that the JSON actions and sources are not pretty printed.

If you provide a <target> in the request path, it is used for any actions that don’t explicitly specify an _index argument.

create #

Indexes the specified document if it does not already exist. The following line must contain the source data to be indexed.

  • _namespace
    (Optional, string) Name of the namespace to perform the action on.
  • _collection
    (Optional, string) Name of the collection to perform the action on. This parameter is required if a <target> is not specified in the request path.
  • _index
    (Optional, string) A shortcut to specify the namespace and collection in [<namespace>:]<collection> syntax. This parameter conflicts with <_namespace> and <_collection>.
  • _id
    (Optional, string) The document ID. If no ID is specified, a document ID is automatically generated.

delete #

Removes the specified document from the index.

  • _namespace
    (Optional, string) Name of the namespace to perform the action on.
  • _collection
    (Optional, string) Name of the collection to perform the action on. This parameter is required if a <target> is not specified in the request path.
  • _index
    (Optional, string) A shortcut to specify the namespace and collection in [<namespace>:]<collection> syntax. This parameter conflicts with <_namespace> and <_collection>.
  • _id
    (Required, string) The document ID. If no ID is specified, a document ID is automatically generated.

index #

Indexes the specified document. If the document exists, replaces the document and increments the version. The following line must contain the source data to be indexed.

  • _namespace
    (Optional, string) Name of the namespace to perform the action on.
  • _collection
    (Optional, string) Name of the collection to perform the action on. This parameter is required if a <target> is not specified in the request path.
  • _index
    (Optional, string) A shortcut to specify the namespace and collection in [<namespace>:]<collection> syntax. This parameter conflicts with <_namespace> and <_collection>.
  • _id
    (Optional, string) The document ID. If no ID is specified, a document ID is automatically generated.

delete #

Removes the specified document from the index.

  • _namespace
    (Optional, string) Name of the namespace to perform the action on.
  • _collection
    (Optional, string) Name of the collection to perform the action on. This parameter is required if a <target> is not specified in the request path.
  • _index
    (Optional, string) A shortcut to specify the namespace and collection in [<namespace>:]<collection> syntax. This parameter conflicts with <_namespace> and <_collection>.
  • _id
    (Required, string) The document ID. If no ID is specified, a document ID is automatically generated.

doc #

The partial document to index. Required for update operations.

<fields> #

The document source to index. Required for create and index operations.