Batch operations

Batch operations are a way to perform multiple operations in a single request. This can be useful for reducing the number of HTTP requests your application makes, which can improve performance and reduce server load.

There are two types of batch operations:

  • Batch read
  • Batch write

In the following sections, we will provide detailed information about how to use these operations.


Batch Read

The Batch read operations allow you to retrieve multiple documents in a single request.


Read Action Attributes

  • Name
    _id
    Type
    required
    Description

    The unique identifier of the Document to be retrieved.

Batch Read action

{
  "_id": "Mnt8qIIBrbFU6hq5wjQx"
}

POST/v1/index/{index-name}/batch

Batch Read Endpoint

This endpoint enables the execution of Batch Read actions.

Parameters

  • Name
    *
    Type
    Description

    An array that contains the batch read actions.

Security

  • Name
    admin
    Type
    API Key
    Description

    This endpoint requires an admin API key.

Returns

Returns an array containing the results for each action specified in the request.

Request

POST
/v1/index/{index-name}/batch
curl -X POST https://sdfzzrn1amg3tbuxb.sigmie.app/v1/index/cosmic-realms/batch \
  -H "Content-Type: application/json" \
  -H "X-Sigmie-API-Key: ${api_key}" \
  -H "X-Sigmie-Application: ${application_id}" \
  -d '[
        {
          "_id": "dHt8qIIBrbFU6hq5wjQx"
        },
        {
          "_id": "h3t8qIIBrbFU6hq5wjQx"
        },
        {
          "_id": "Mnt8qIIBrbFU6hq5wjQx"
        }
  ]'

Response

200
Ok
[
  {
    "_id": "dHt8qIIBrbFU6hq5wjQx",
    "name": "Andromeda Galaxy",
    "type": "Galaxy",
    "age": "Approximately 10 billion years",
    "size": "Approximately 220,000 light-years in diameter"
  },
  {
    "_id": "h3t8qIIBrbFU6hq5wjQx",
    "name": "Orion Nebula",
    "type": "Nebula",
    "age": "Approximately 1-3 million years",
    "size": "Approximately 24 light-years in diameter"
  },
  {
    "_id": "Mnt8qIIBrbFU6hq5wjQx",
    "name": "Pillars of Creation",
    "type": "Nebula",
    "age": "Estimated to be about 5.5 million years",
    "size": "Approximately 4 light-years tall"
  }
]

Batch Write

Batch write operations allow you to upsert, patch, and delete multiple Documents in a single request.


Upsert Action Attributes

  • Name
    action
    Type
    required
    Description

    This should be upsert.

  • Name
    _id
    Type
    optional
    Description

    The unique identifier of the Document to be upserted.

  • Name
    body
    Type
    required
    Description

    The body of the Document to be upserted.

Batch Upsert action

{
  "action": "upsert",
  "_id": "j8lmj4EBetGDRrvvlbNf",
  "body": {
    "name": "Pillars of Creation",
    "description": "A region in the Eagle Nebula where new stars are being formed, characterized by towering columns of gas and dust.",
    "type": "Nebula",
    "age": "Estimated to be about 5.5 million years",
    "size": "Approximately 4 light-years tall"
  }
}

Patch Action Attributes

  • Name
    action
    Type
    required
    Description

    This should be patch.

  • Name
    body
    Type
    required
    Description

    The body of the Document to be patched.

  • Name
    _id
    Type
    required
    Description

    The unique identifier of the Document to be patched.

Batch Patch body

{
  "action": "patch",
  "_id": "9q6Sy4MBs1uM0PSSE68v",
  "body": {
    "name": "Orion Nebula",
    "description": "A diffuse nebula located in the constellation of Orion, known for its star-forming activity.",
    "type": "Nebula",
    "age": "Approximately 1-3 million years",
    "size": "Approximately 24 light-years in diameter"
  }
}

Delete Action Attributes

  • Name
    action
    Type
    required
    Description

    This should be delete.

  • Name
    _id
    Type
    required
    Description

    The unique identifier of the Document to be deleted.

Batch Write body

{
  "action": "delete",
  "_id": "9q6Sy4MBs1uM0PSSE68v"
}

PUT/v1/index/{index-name}/batch

Batch Write Endpoint

This endpoint allows you to run batch actions.

Parameters

  • Name
    *
    Type
    Description

    An array that contains the batch write actions.

Security

  • Name
    admin
    Type
    API Key
    Description

    This endpoint requires an admin API key.

Returns

Returns an array containing the results for each action specified in the request.

Request

PUT
/v1/index/{index-name}/batch
curl -X PUT https://sdfzzrn1amg3tbuxb.sigmie.app/v1/index/cosmic-realms/batch \
  -H "Content-Type: application/json" \
  -H "X-Sigmie-API-Key: ${api_key}" \
  -H "X-Sigmie-Application: ${application_id}" \
  -d '[
    {
      "action": "create",
      "body": {
        "name": "Orion Nebula"
      }
    },
    {
      "action": "update",
      "_id": "9q6Sy4MBs1uM0PSSE68v",
      "body": {
        "name": "Pillars of Creation"
      }
    },
    {
      "action": "delete",
      "_id": "PkOoIBJq3of4094YiE"
    }
  ]'

Response

200
Ok
[
  {
    "_id": "j8lmj4EBetGDRrvvlbNf",
    "result": "created"
  },
  {
    "_id": "9q6Sy4MBs1uM0PSSE68v",
    "result": "updated"
  },
  {
    "_id": "PkOoIBJq3of4094YiE",
    "result": "deleted"
  }
]