Skip to content

Projection

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Projection is choosing which data is returned from each matching record, analogous to choosing columns in a relational database using SELECT. Aerospike distinguishes two types of projection:

  • Bin projection — Return values from one or more named bins (a vertical subset of the record’s bin data).
  • Operation projection — Return the results of read-only bin operations, including simple bin reads, path expressions, and other read operations described under operation expressions. This supports nested paths, computed values, and lightweight server-side shaping without an extra round trip.

The Java SDK and Python SDK tabs use Developer SDK AEL text where it can express the example; the other tabs build the same expression with their client’s Exp builder. See the AEL reference and Query records in the Developer SDK.

Uniform API across commands

Single-record operate and batched operate have always supported both bin projection and operation projection in one command: you specify an ordered list of read operations, which can be plain bin reads or richer read operations.

Prior to Aerospike Database 8.1.2, foreground queries supported only a list of bin names (bin projection). Starting with 8.1.2, queries also support operation projection, so the query result shape matches what you can request from operate on a single key or in a batch.

Specifying a list of bin names for projection remains supported. Performance of that form is equivalent to using corresponding bin read operations in the projection list.

Benefits

  • Unified API: Queries behave like batched operations for projections, with a predictable interface across single-key, batch, and query commands.
  • Path expressions in query projection: Use path expressions and other expression APIs in the projection, not just in the filter selection.
  • Server-side computation: Offload lightweight transformations, arithmetic, and aggregations to the server; only requested bins or results are sent back.
  • Lower latency: Avoid the two-phase query-then-batch pattern; one query returns the projected data.

Supported projection operations

Query projection accepts read-only operations:

  • Bin read operations: Operation.get(binName) or equivalent in your client. Equivalent to specifying bin names.
  • CDT read operations: Map and List read operations (e.g., MapOperation.getByKey, ListOperation.getByIndex).
  • Read expressions: Operation expressions that compute a value and return it in a computed bin via ExpOperation.read().

Example: Replacing the two-phase pattern

Before (two-phase): Query with no bins to get keys, then operate batched commands to get projected data.

DataSet reports = DataSet.of("test", "reports");
// Phase 1: Query returns only keys (no bin data)
List<Key> keysList = new ArrayList<>();
try (RecordStream rs = session.query(reports).withNoBins().execute()) {
rs.forEach(result -> keysList.add(result.getKey()));
}
// Phase 2: Batch operate to get city and state from report map
try (RecordStream rs = session.query(keysList)
.bin("report").onMapKeyList(List.of("city", "state")).getValues()
.execute()) {
rs.forEach(result -> System.out.println(result.recordOrThrow().getList("report")));
}

After (single query with projection ops): One query returns the projected data.

DataSet reports = DataSet.of("test", "reports");
try (RecordStream rs = session.query(reports)
.bin("report").onMapKeyList(List.of("city", "state")).getValues()
.execute()) {
rs.forEach(result -> System.out.println(result.recordOrThrow().getList("report")));
}

Example: Read expression in projection

Use a read expression to compute a value and return it in a computed bin:

DataSet reports = DataSet.of("test", "reports");
RecordStream stream = session.query(reports)
.bin("daysToPost").selectFrom("$.posted:INT - $.occurred:INT")
.execute();
stream.forEach(result -> {
Record rec = result.recordOrThrow();
System.out.println(rec.getLong("daysToPost"));
});
stream.close();