Skip to content

List expressions

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

List expressions read and modify list values inside an expression tree. For the data type itself and its Operate API, see List.

Read expressions (list_size, list_get_by_index, list_get_by_value, the rank and range variants) evaluate to whatever result_type selects — a count, an index, a rank, or a value. That makes them projection: they shape what a command returns for each record, in operate, in a batch, and in a query. Wrap one in comparison or logic to get the Boolean a record filter needs.

Modify expressions (list_append, list_insert, list_remove_by_*, list_set, list_increment, list_sort, list_clear) evaluate to a new list and leave the record untouched. Storing that value takes a write operation expression; see Operations and expressions for how the two APIs differ.

A list operand is a bin, read with bin_list, or any expression that evaluates to a list. Reading stored data can evaluate to unknown; see Unknown results.

For nested collection data and path filters, see Querying collection data types and Path expressions.

The Developer SDK’s AEL text syntax expresses the same list operations as path functions, for example $.tags.append('new').

Composing expressions

An expression evaluates to a value, and that value is what the next expression operates on — see Expressions compose.

Every list operation takes its bin operand that way: not only a named list bin, but the result of any expression evaluating to a list. list_append shows the pattern — its example takes the list_size of the appended-to list, so the size counts the new element while the record keeps the original.

Two differences from the CDT List API

  • A list modify expression evaluates to the whole modified list. The matching CDT List operation returns something narrower and operation-specific: append returns the new element count, and the remove-by operations return what result_type selects.

  • The single-element getters, list_get_by_index and list_get_by_rank, take a type argument in addition to result_type. A list element can be of any type, and an expression is strictly typed, so the getter has to declare the type it evaluates to. Reading an element of another type fails the expression.

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 list_get_by_value 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.

Each operation’s Example shows the code in nine tabs: Aerospike Expression Language (AEL) text on the Java SDK and Python SDK tabs, and the Exp builder on the other seven. See the AEL reference for AEL grammar.

Modify

list_append

list_append(context, policy, value, bin)
Description

Returns the list with value appended to the end. It does not create a bin that does not exist, unlike the append CDT List operation, which does.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

policyList policy

Write flags for the operation. See Write flags. A violated flag fails the expression, unless no_fail is set, in which case the list comes back unchanged. The policy’s ordering attribute has no effect here: order is fixed when a list is created, and an expression never creates one.

valueany

Element to append to the list.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.append('horror').count() > 2";

list_append_items

list_append_items(context, policy, items, bin)
Description

Returns the list with every element of items appended to the end.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

policyList policy

Write flags for the operation. See Write flags. A violated flag fails the expression, unless no_fail is set, in which case the list comes back unchanged. The policy’s ordering attribute has no effect here: order is fixed when a list is created, and an expression never creates one.

itemslist

Elements to append, as a list.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

Size check after appending two strings to tags.

String exp = "$.tags.appendItems(['a', 'b']).count() > 3";

list_clear

list_clear(context, bin)
Description

Returns the list with all elements removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

Cleared list has size 0.

String exp = "$.tags.clear().count() == 0";

list_increment

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

Returns the list with the element at index increased by delta.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

policyList policy

Write flags for the operation. See Write flags. A violated flag fails the expression, unless no_fail is set, in which case the list comes back unchanged. The policy’s ordering attribute has no effect here: order is fixed when a list is created, and an expression never creates one.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

deltainteger or float

Amount to add to the element at index. A negative value subtracts. The element’s own type governs: a float added to an integer element is truncated toward zero first, so adding 1.5 adds 1 and adding 0.5 leaves it unchanged.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Operate API operation
Example

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

String exp = "($.scores.[0].add(5)).[0] == 100";

list_insert

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

Returns the list with value inserted at index.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

policyList policy

Write flags for the operation. See Write flags. A violated flag fails the expression, unless no_fail is set, in which case the list comes back unchanged. The policy’s ordering attribute has no effect here: order is fixed when a list is created, and an expression never creates one.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

valueany

Element to insert at index.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[0].insert('prologue').count() > 1";

list_insert_items

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

Returns the list with every element of items inserted at index.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

policyList policy

Write flags for the operation. See Write flags. A violated flag fails the expression, unless no_fail is set, in which case the list comes back unchanged. The policy’s ordering attribute has no effect here: order is fixed when a list is created, and an expression never creates one.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

itemslist

Elements to insert at index, as a list.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[1].insertItems(['x', 'y']).count() > 4";

list_remove_by_index

list_remove_by_index(context, index, bin)
Description

Returns the list with the element at index removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

After removing index 0 from tags, length is 2.

String exp = "$.tags.[0].remove().count() == 2";

list_remove_by_index_range

list_remove_by_index_range(context, index, count, bin)
Description

Returns the list with count elements removed, starting at index.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

countinteger

Number of elements in the range.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

Remove two elements starting at index 0 from tags.

String exp = "$.tags.[0:2].remove().count() > 0";

list_remove_by_index_range_to_end

list_remove_by_index_range_to_end(context, index, bin)
Description

Returns the list with every element from index to the end removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[2:].remove().count() > 0";

list_remove_by_rank

list_remove_by_rank(context, rank, bin)
Description

Returns the list with the element of rank rank removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0].remove().count() > 0";

list_remove_by_rank_range

list_remove_by_rank_range(context, rank, count, bin)
Description

Returns the list with count elements removed, starting at rank rank.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

countinteger

Number of elements in the range.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0:2].remove().count() > 0";

list_remove_by_rank_range_to_end

list_remove_by_rank_range_to_end(context, rank, bin)
Description

Returns the list with every element of rank rank or higher removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#-2:].remove().count() > 0";

list_remove_by_rel_rank_range

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

Returns the list with count elements removed, starting at the rank rank places from value.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

valueany

Value that rank is measured from. It need not be present in the collection — the rank is taken from where it would sort.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

countinteger

Number of elements in the range.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0:1~10].remove().count() > 0";

list_remove_by_rel_rank_range_to_end

list_remove_by_rel_rank_range_to_end(context, value, rank, bin)
Description

Returns the list with every element from the rank rank places from value to the highest rank removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

valueany

Value that rank is measured from. It need not be present in the collection — the rank is taken from where it would sort.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0:~10].remove().count() > 0";

list_remove_by_value

list_remove_by_value(context, value, bin)
Description

Returns the list with every element equal to value removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

valueany

Value to match. Every element equal to it is removed.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[='draft'].remove().count() > 0";

list_remove_by_value_list

list_remove_by_value_list(context, values, bin)
Description

Returns the list with every element matching one of values removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

valueslist

Values to match. Any element equal to one of these is removed.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[='a', 'b'].remove().count() > 0";

list_remove_by_value_range

list_remove_by_value_range(context, value_begin, value_end, bin)
Description

Returns the list with every element in the interval value_begin ≤ x < value_end removed.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

value_beginany

Lowest value to match, inclusive.

value_endany

Upper bound on the value, exclusive. Omit it to match everything from value_begin upward.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[=10:20].remove().count() > 0";

list_set

list_set(context, index, value, bin)
Description

Returns the list with the element at index replaced by value.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

valueany

Element to write at index, replacing what is there.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation

set

Example

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

String exp = "($.scores.[1].setTo(99)).[1] == 99";

list_sort

list_sort(context, sort_flags, bin)
Description

Returns the list in sorted order, as directed by sort_flags.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

sort_flagsinteger literal

Sort flags: 0 sorts ascending, 2 sorts ascending and drops duplicate values.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
list
Introduced
5.2.0.4
Operate API operation
Example

After the default ascending sort, the first element of scores is 0.

String exp = "($.scores.sort()).[0] == 0";

Read

list_get_by_index

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

Returns the element at index.

Arguments
NameTypeDescription
typeinteger literal

Data type of the element being read. Expressions are strictly typed, so this getter declares the type it evaluates to; an element of another type fails the expression.

contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[0] == 42";

list_get_by_index_range

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

Returns count elements starting at index.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

countinteger

Number of elements in the range.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[1:3].count() == 2";

list_get_by_index_range_to_end

list_get_by_index_range_to_end(context, result_type, index, bin)
Description

Returns every element from index to the end.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

indexinteger

Zero-based position in the collection, 0 being the first element. A negative index counts back from the end.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[2:].count() == 1";

list_get_by_rank

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

Returns the element of rank rank.

Arguments
NameTypeDescription
typeinteger literal

Data type of the element being read. Expressions are strictly typed, so this getter declares the type it evaluates to; an element of another type fails the expression.

contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0] == 12";

list_get_by_rank_range

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

Returns count elements starting at rank rank.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

countinteger

Number of elements in the range.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Operate API operation
Example

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

String exp = "$.scores.[#0:3].count() == 3";

list_get_by_rank_range_to_end

list_get_by_rank_range_to_end(context, result_type, rank, bin)
Description

Returns every element of rank rank or higher.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#-2:].count() == 2";

list_get_by_rel_rank_range

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

Returns count elements starting at the rank rank places from value.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

valueany

Value that rank is measured from. It need not be present in the collection — the rank is taken from where it would sort.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

countinteger

Number of elements in the range.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0:2~15].count() > 0";

list_get_by_rel_rank_range_to_end

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

Returns every element from the rank rank places from value to the highest rank.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

valueany

Value that rank is measured from. It need not be present in the collection — the rank is taken from where it would sort.

rankinteger

Rank of the element in value order, 0 being the smallest. A negative rank counts back from the largest.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[#0:~15].count() > 0";

list_get_by_value

list_get_by_value(context, result_type, value, bin)
Description

Returns every element equal to value.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

valueany

Value to match. Every element equal to it is selected.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags.[='fiction'].exists()";

list_get_by_value_list

list_get_by_value_list(context, result_type, values, bin)
Description

Returns every element matching one of values.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

valueslist

Values to match, as a list. Every element equal to any of them is selected.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[=88, 94].count() > 0";

list_get_by_value_range

list_get_by_value_range(context, result_type, value_begin, value_end, bin)
Description

Returns every element in the interval value_begin ≤ x < value_end.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

result_typeinteger literal

Which form the result takes, such as count, index, rank, or value. See Return types.

value_beginany

Lowest value to match, inclusive.

value_endany

Upper bound on the value, exclusive. Omit it to match everything from value_begin upward.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
any
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.scores.[=10:50].count() > 0";

list_join

list_join(context, separator, bin)
Description

Returns the list’s string elements joined into one string. Every client also exposes a form that takes no separator, concatenating the elements with nothing between them.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

separatorstring

String placed between elements. Omit it to join them with nothing in between.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
string
Introduced
8.2.0
Operate API operation
Example

Filter records whose list bin tags, joined with ,, equals red,green,blue.

String exp = "$.tags.join(',') == 'red,green,blue'";

list_size

list_size(context, bin)
Description

Returns the number of elements in the list.

Arguments
NameTypeDescription
contextContext instance

Optional context path selecting a List or Map nested inside the operand. Omit it to operate on the top level.

binlist

List bin to operate on, or any expression that evaluates to a list.

Returns
integer
Introduced
5.2.0.4
Operate API operation
Example

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

String exp = "$.tags:LIST.count() > 0";