Skip to content

List bin operations

Aerospike list bin expressions read and modify list-type bins inside filter, operation, and projection pipelines. Use them with comparison and logic expressions when you need a boolean filter, or compose them with record storage typed-bin readers (bin_list) when you need the list value first.

In each operation, the list operand (list_bin_expr in the argument tables) is any list-valued expression: not only a named list bin, but also the result of another expression that evaluates to a list. List operations compose by passing those values as the list input—for example, taking the size of a list after an append. For nested collection data and path filters, see Querying collection data types and Path expressions.

Composing expressions

The list_append reference includes an Example that wraps ListExp.append in ListExp.size—the same modify-then-read pattern described above. Many other modify operations show similar composition: their examples nest another list expression as the list operand (list_bin_expr in the arguments table).

This reference covers read operations (size, get-by-index, get-by-value, rank and range variants) and modify operations (append, insert, remove, set, increment, sort, and clear). List modify expressions evaluate on a temporary list value; they do not persist unless used in a write pipeline that stores the result.

  • List modify expressions differ from CDT List operations in that they return the modified list-bin instead of a specified return type (for remove-by ops) or predefined return type (The CDT operation append returns an int for example).

  • List read expressions (other than LIST_SIZE) return a result based on their integer_value parameter.

    Calling single result CDT operations (e.g. LIST_GET_BY_INDEX) requires an integer_value when integer_value is LIST_RETURN_VALUE because a list element value can be any expression type.

Path expressions

List expressions such as list_get_by_value can be used inside path expression filter contexts. For example, the IN-list membership pattern uses ListExp.getByValue with a loop variable to check whether a map key belongs to a given list of IDs. See the path expressions performance page for a detailed comparison of IN-list filtering approaches.

Modify

list_append

list_append(context, policy, value, bin)
Description

Append value to list bin. list_append does not create a new bin if the specified bin does not exist, unlike the append CDT List operation, which does create a new bin if the specified bin does not exist.

Arguments
NameType
context library_specific
policy library_specific
value expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Hypothetical filter using the list after appending horror to tags (modify expressions evaluate on a temporary list value).

import com.aerospike.client.cdt.ListPolicy;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.append(ListPolicy.Default, Exp.val("horror"), Exp.listBin("tags"))),
Exp.val(2)));

list_append_items

list_append_items(context, policy, values, bin)
Description

Append all elements in values to list bin.

Arguments
NameType
context library_specific
policy library_specific
values list_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Size check after appending two strings to tags.

import com.aerospike.client.cdt.ListPolicy;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.appendItems(
ListPolicy.Default,
Exp.val(java.util.Arrays.asList("a", "b")),
Exp.listBin("tags"))),
Exp.val(3)));

list_clear

list_clear(context, bin)
Description

Clear all elements in list bin.

Arguments
NameType
context library_specific
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Cleared list has size 0.

import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(ListExp.size(ListExp.clear(Exp.listBin("tags"))), Exp.val(0)));

list_increment

list_increment(context, policy, index, delta, bin)
Description

Increment element at index by delta.

Arguments
NameType
context library_specific
policy library_specific
index integer_expr
delta integer_expr
bin list_bin_expr
Returns
list_bin
Example

After adding 5 to scores[0], the first element equals 100.

import com.aerospike.client.cdt.ListPolicy;
import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByIndex(
ListReturnType.VALUE,
Exp.Type.INT,
Exp.val(0),
ListExp.increment(ListPolicy.Default, Exp.val(0), Exp.val(5), Exp.listBin("scores"))),
Exp.val(100)));

list_insert

list_insert(context, policy, index, value, bin)
Description

Insert value at index.

Arguments
NameType
context library_specific
policy library_specific
index integer_expr
value expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Insert prologue at index 0 in tags, then require length > 1.

import com.aerospike.client.cdt.ListPolicy;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.insert(ListPolicy.Default, Exp.val(0), Exp.val("prologue"), Exp.listBin("tags"))),
Exp.val(1)));

list_insert_items

list_insert_items(context, policy, index, values, bin)
Description

Insert all elements in values at index.

Arguments
NameType
context library_specific
policy library_specific
index integer_expr
values list_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Insert [“x”,“y”] at index 1 in tags.

import com.aerospike.client.cdt.ListPolicy;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.insertItems(
ListPolicy.Default,
Exp.val(1),
Exp.val(java.util.Arrays.asList("x", "y")),
Exp.listBin("tags"))),
Exp.val(4)));

list_remove_by_index

list_remove_by_index(context, index, bin)
Description

Remove element at index.

Arguments
NameType
context library_specific
index integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

After removing index 0 from tags, length is 2.

import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.size(ListExp.removeByIndex(Exp.val(0), Exp.listBin("tags"))),
Exp.val(2)));

list_remove_by_index_range

list_remove_by_index_range(context, index, count, bin)
Description

Remove count element at index.

Arguments
NameType
context library_specific
index integer_expr
count integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove two elements starting at index 0 from tags.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByIndexRange(
ListReturnType.NONE, Exp.val(0), Exp.val(2), Exp.listBin("tags"))),
Exp.val(0)));

list_remove_by_index_range_to_end

list_remove_by_index_range_to_end(context, index, bin)
Description

Remove all elements at and after index.

Arguments
NameType
context library_specific
index integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove from index 2 through end of tags; resulting list still has elements.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByIndexRange(ListReturnType.NONE, Exp.val(2), Exp.listBin("tags"))),
Exp.val(0)));

list_remove_by_rank

list_remove_by_rank(context, rank, bin)
Description

Remove all element with rank rank.

Arguments
NameType
context library_specific
rank integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove the smallest score (rank 0) and keep a non-empty list.

import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(ListExp.removeByRank(Exp.val(0), Exp.listBin("scores"))),
Exp.val(0)));

list_remove_by_rank_range

list_remove_by_rank_range(context, rank, count, bin)
Description

Remove count element at rank.

Arguments
NameType
context library_specific
rank integer_expr
count integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove the two smallest scores (rank 0, count 2).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByRankRange(
ListReturnType.NONE, Exp.val(0), Exp.val(2), Exp.listBin("scores"))),
Exp.val(0)));

list_remove_by_rank_range_to_end

list_remove_by_rank_range_to_end(context, rank, bin)
Description

Remove all elements at and after rank.

Arguments
NameType
context library_specific
rank integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove the two largest scores (rank -2 through last).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByRankRange(ListReturnType.NONE, Exp.val(-2), Exp.listBin("scores"))),
Exp.val(0)));

list_remove_by_rel_rank_range

list_remove_by_rel_rank_range(context, value, rank, count, bin)
Description

Remove count element at rank relative to value.

Arguments
NameType
context library_specific
value expr
rank integer_expr
count integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove at most two elements relative to value 10 (rank offset 0) in scores.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByValueRelativeRankRange(
ListReturnType.NONE,
Exp.val(10),
Exp.val(0),
Exp.val(2),
Exp.listBin("scores"))),
Exp.val(0)));

list_remove_by_rel_rank_range_to_end

list_remove_by_rel_rank_range_to_end(context, value, rank, bin)
Description

Remove all elements at and after rank relative to value.

Arguments
NameType
context library_specific
value expr
rank integer_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove by relative rank from value 10, rank offset 0, through end of scores.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByValueRelativeRankRange(
ListReturnType.NONE, Exp.val(10), Exp.val(0), Exp.listBin("scores"))),
Exp.val(0)));

list_remove_by_value

list_remove_by_value(context, value, bin)
Description

Remove all value values from list.

Arguments
NameType
context library_specific
value expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

After removing draft from tags, the list is still non-empty.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByValue(ListReturnType.NONE, Exp.val("draft"), Exp.listBin("tags"))),
Exp.val(0)));

list_remove_by_value_list

list_remove_by_value_list(context, value, bin)
Description

Remove all elements with values in value_list from list.

Arguments
NameType
context library_specific
value list_expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

After removing values a and b from tags, size remains > 0.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByValueList(
ListReturnType.NONE,
Exp.val(java.util.Arrays.asList("a", "b")),
Exp.listBin("tags"))),
Exp.val(0)));

list_remove_by_value_range

list_remove_by_value_range(context, start, end, bin)
Description

Remove all elements x in interval start ≤ x < end from list.

Arguments
NameType
context library_specific
start expr
end expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

Remove integer scores in [10, 20) and check the modified list still has elements.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.size(
ListExp.removeByValueRange(
ListReturnType.NONE, Exp.val(10), Exp.val(20), Exp.listBin("scores"))),
Exp.val(0)));

list_set

list_set(context, index, value, bin)
Description

Set element at index to value.

Arguments
NameType
context library_specific
index integer-expr
value expr
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

After setting scores[1] to 99, read back 99 at index 1.

import com.aerospike.client.cdt.ListPolicy;
import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByIndex(
ListReturnType.VALUE,
Exp.Type.INT,
Exp.val(1),
ListExp.set(ListPolicy.Default, Exp.val(1), Exp.val(99), Exp.listBin("scores"))),
Exp.val(99)));

list_sort

list_sort(context, flag, bin)
Description

Sort list.

Arguments
NameType
context library_specific
flag integer
bin list_bin_expr
Returns
list_bin
Introduced
5.2.0.4
Example

After default ascending sort, the smallest element in scores is 0.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.cdt.ListSortFlags;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByRank(
ListReturnType.VALUE,
Exp.Type.INT,
Exp.val(0),
ListExp.sort(ListSortFlags.DEFAULT, Exp.listBin("scores"))),
Exp.val(0)));

Read

list_get_by_index

list_get_by_index(type, context, result_type, index, bin)
Description

Get element at index.

Arguments
NameType
type integer_value
context library_specific
result_type integer_value
index integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

First element of integer list scores equals 42 (LIST_RETURN_VALUE with integer value type).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByIndex(
ListReturnType.VALUE, Exp.Type.INT, Exp.val(0), Exp.listBin("scores")),
Exp.val(42)));

list_get_by_index_range

list_get_by_index_range(context, result_type, index, count, bin)
Description

Get count elements at index.

Arguments
NameType
context library_specific
result_type integer_value
index integer_expr
count integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Exactly two elements starting at index 1 in scores (LIST_RETURN_COUNT with index 1 and count 2).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByIndexRange(
ListReturnType.COUNT, Exp.val(1), Exp.val(2), Exp.listBin("scores")),
Exp.val(2)));

list_get_by_index_range_to_end

list_get_by_index_range_to_end(context, result_type, index, bin)
Description

Get elements at and after index.

Arguments
NameType
context library_specific
result_type integer_value
index integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Count of elements from index 2 through the end of tags (LIST_RETURN_COUNT).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByIndexRange(ListReturnType.COUNT, Exp.val(2), Exp.listBin("tags")),
Exp.val(1)));

list_get_by_rank

list_get_by_rank(type, context, result_type, rank, bin)
Description

Get element at rank.

Arguments
NameType
type integer_value
context library_specific
result_type integer_value
rank integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Smallest value in ordered integer list scores is 12 (rank 0, LIST_RETURN_VALUE).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByRank(ListReturnType.VALUE, Exp.Type.INT, Exp.val(0), Exp.listBin("scores")),
Exp.val(12)));

list_get_by_rank_range

list_get_by_rank_range(context, result_type, rank, count, bin)
Description

Get count elements at rank.

Arguments
NameType
context library_specific
result_type integer_value
rank integer_expr
count integer_expr
bin list_bin_expr
Example

Three smallest values in scores (rank 0, count 3, LIST_RETURN_COUNT).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByRankRange(
ListReturnType.COUNT, Exp.val(0), Exp.val(3), Exp.listBin("scores")),
Exp.val(3)));

list_get_by_rank_range_to_end

list_get_by_rank_range_to_end(context, result_type, rank, bin)
Description

Get elements at and after rank.

Arguments
NameType
context library_specific
result_type integer_value
rank integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Two largest values in scores (rank -2 through last, LIST_RETURN_COUNT).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.eq(
ListExp.getByRankRange(ListReturnType.COUNT, Exp.val(-2), Exp.listBin("scores")),
Exp.val(2)));

list_get_by_rel_rank_range

list_get_by_rel_rank_range(context, result_type, value, rank, count, bin)
Description

Get count element at rank relative to value.

Arguments
NameType
context library_specific
result_type integer_value
value expr
rank integer_expr
count integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Count of elements selected by relative rank range from value 15 (rank offset 0, max 3 items) in scores.

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.getByValueRelativeRankRange(
ListReturnType.COUNT,
Exp.val(15),
Exp.val(0),
Exp.val(3),
Exp.listBin("scores")),
Exp.val(0)));

list_get_by_rel_rank_range_to_end

list_get_by_rel_rank_range_to_end(context, result_type, value, rank, bin)
Description

Get all elements at and after rank relative to value.

Arguments
NameType
context library_specific
result_type integer_value
value expr
rank integer_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Relative rank range from value 15 with rank offset 0 through end of scores (LIST_RETURN_COUNT > 0).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.getByValueRelativeRankRange(
ListReturnType.COUNT, Exp.val(15), Exp.val(0), Exp.listBin("scores")),
Exp.val(0)));

list_get_by_value

list_get_by_value(context, result_type, value, bin)
Description

Get all value values from list.

Arguments
NameType
context library_specific
result_type integer_value
value expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Filter where string list bin tags contains the value fiction, using LIST_RETURN_EXISTS (see also the path expressions IN-list membership pattern).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
ListExp.getByValue(ListReturnType.EXISTS, Exp.val("fiction"), Exp.listBin("tags")));

list_get_by_value_list

list_get_by_value_list(context, result_type, values, bin)
Description

Get all elements with values in values from list.

Arguments
NameType
context library_specific
result_type integer_value
values list_expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Integer scores in scores where at least one value matches the list [88, 94] (using LIST_RETURN_COUNT > 0).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.getByValueList(
ListReturnType.COUNT,
Exp.val(java.util.Arrays.asList(88, 94)),
Exp.listBin("scores")),
Exp.val(0)));

list_get_by_value_range

list_get_by_value_range(context, result_type, start, end, bin)
Description

Get all elements x in interval start ≤ x < end from list.

Arguments
NameType
context library_specific
result_type integer_value
start expr
end expr
bin list_bin_expr
Introduced
5.2.0.4
Example

Integer list scores with values in the half-open interval [10, 50) (using LIST_RETURN_COUNT).

import com.aerospike.client.cdt.ListReturnType;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(
ListExp.getByValueRange(
ListReturnType.COUNT, Exp.val(10), Exp.val(50), Exp.listBin("scores")),
Exp.val(0)));

list_size

list_size(context, bin)
Description

Get list element count.

Arguments
NameType
context library_specific
bin list_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Filter records whose list bin tags is non-empty (same pattern as bin_list with size).

import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.ListExp;
Expression exp = Exp.build(
Exp.gt(ListExp.size(Exp.listBin("tags")), Exp.val(0)));
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?