Skip to main content

Batch Operations

Jump to the Code block for a combined complete example.

Batch Operations are operations on multiple records issued as a single request. Batch reads support get, exists, getHeader, and operate requests. Batch writes, introduced in Aerospike 6.0, allow write requests against any keys, including updates, deletes, UDFs, and multi-operation transactions.

Setup

The following examples will use the setup and record structure below to illustrate batch operations in an Aerospike database.

The record structure:

Occurred: Integer  
Reported: Integer
Posted: Integer
Report: Map
{
shape: List,
summary: String,
city: String,
state: String,
duration: String
}
Location: GeoJSON

Policies

Policies are defined for the batch parent policy as well as batch read, batch write, batch delete, and batch UDF operations. Filter Expressions can be defined within each type of batch operation policy and the batch parent policy, along with other operation specific policies.

Requests

Exists

The following example creates an array of ten keys and checks for their existance in the database.

Read records

The following example creates an array of ten keys and reads the records from the database; returning either the whole record or the specified report and location bins.

Read operations

The following example creates an array of ten keys and accesses the city and state map keys to return their respective values from the report bin, for each record.

Read/write operations

The following example creates an array of ten keys and

  1. Defines an Operation Expression that compares the occurred bin value against the provided value, 20211231, and verifies the posted bin exists to determine the boolean value of the new recent key being added to the report map.
  2. Returns the report bin.

Delete operations

The following example deletes the records from the database.

Complex mixed operations

The following example creates a list of four batch records that each use a differing set of operations.

The record with user defined key 4000

  1. uses the ops1 array that combines the Operation Expression.
  2. uses exp1 which compares the occurred bin value against the provided value, 20211231 and verifies the posted bin exists to determine the boolean value of the new recent key being added to the report map.
  3. returns the report bin.

The record with user defined key 4001

  1. uses the ops2 array which contains a read Operation Expression that gets the length of the shape list from the report map and returns the value in a synthetic bin named numShapes.

The record with user defined key 4002

  1. uses the ops3 array which combines a write operation that updates the posted bin value, with a map operation that updates the city value in the report map.
  2. returns both the posted and report bins.

The record with user defined key 4003 is deleted from the database.

Code block

Expand this section for a single code block to execute a batch read/write operation