Skip to content

Comparison

Comparison expressions evaluate to a boolean (true or false). You use them anywhere filter expressions are allowed—for example record filters on single-key, batch, scan, and query operations; FilterExpression on query and batch policies; XDR filters; and operation expressions (read/write expression ops) where the API expects a boolean.

Operands must have the same fundamental type (for example, both integers or both strings). If types do not match, behavior follows the expression type rules for your client; see the overview on expression types and strict typing.

Together with logical operators, comparisons drive most record selection. When a comparison (or its inputs) cannot be resolved in the metadata-only phase, the result may be unknown until storage is read; see the execution model on the expressions overview.

This reference covers the wire-level operators eq, ne, lt, gt, le, ge, cmp_regex, cmp_geo, and the in_list membership test (server 8.1.2+). The examples use bins and thresholds aligned with the bookstore scenario on the path expressions page where it helps readability.

Ops

cmp_geo

cmp_geo(left, right)
Description

Returns true if the left is either contained within or contains the right.

Arguments
NameType
left geojson_expr
right geojson_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where GeoJSON bin region contains the given point (San Francisco Bay area). The point is standard GeoJSON; escape quotes as needed in your language.

String point = "{\"type\":\"Point\",\"coordinates\":[-122.4,37.8]}";
Expression exp = Exp.build(
Exp.geoCompare(Exp.geo(point), Exp.geoBin("region")));

cmp_regex

cmp_regex(options_value, regex_string, string)
Description

Returns true if the regex_string matches the string, otherwise returns false.

Arguments
NameType
regex_string string_value
options_value integer_value
string string_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where string bin phone_num starts with area code 555.

// import com.aerospike.client.query.RegexFlag;
Expression exp = Exp.build(
Exp.regexCompare("^555.*", RegexFlag.NONE, Exp.stringBin("phone_num")));

eq

eq(left, right)
Description

Returns true if the left is equal to the right, otherwise returns false. left and right must result in the same fundamental type.

Note that an expression that uses the eq operator to compare two unordered maps, or an ordered map with an unordered map, returns false if the maps contain the same elements in different orders.

Arguments
NameType
left expr
right expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where string bin category equals fiction, matching the bookstore example on the path expressions overview.

Expression exp = Exp.build(
Exp.eq(Exp.stringBin("category"), Exp.val("fiction")));

ge

ge(left, right)
Description

Returns true if the left is greater than or equal to the right, otherwise returns false. left and right must result in the same fundamental type.

Arguments
NameType
left expr
right expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where integer bin quantity is at least 1 (in-stock style), aligned with variant quantity fields in the path quickstart inventory example.

Expression exp = Exp.build(
Exp.ge(Exp.intBin("quantity"), Exp.val(1)));

gt

gt(left, right)
Description

Returns true if the left is greater than the right, otherwise returns false. left and right must result in the same fundamental type.

Arguments
NameType
left expr
right expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where the time-to-live (TTL) is greater than one year (365 days in seconds).

Expression exp = Exp.build(
Exp.gt(Exp.ttl(), Exp.val(365 * 24 * 3600)));

in_list

in_list(value, list)
Description

Returns true if value is contained in list, otherwise returns false.

Arguments
NameType
value expr
list list_expr
Returns
boolean_value
Introduced
8.1.2
Example

Filter records where string bin color is one of “red”, “blue”, or “green”.

import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import java.util.List;
Expression exp = Exp.build(
Exp.inList(
Exp.stringBin("color"),
Exp.val(List.of("red", "blue", "green"))));

le

le(left, right)
Description

Returns true if the left is less than or equal to the right, otherwise returns false. left and right must result in the same fundamental type.

Arguments
NameType
left expr
right expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where integer bin quantity is at most 100 (cap on on-hand units), consistent with inventory-style bins in the path documentation.

Expression exp = Exp.build(
Exp.le(Exp.intBin("quantity"), Exp.val(100)));

lt

lt(left, right)
Description

Returns true if the left is less than the right, otherwise returns false. left and right must result in the same fundamental type.

Arguments
NameType
left expr
right expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where float bin price is strictly below 10—the same “cheap book” threshold used in the bookstore example on the path expressions overview.

Expression exp = Exp.build(
Exp.lt(Exp.floatBin("price"), Exp.val(10.0)));

ne

ne(left, right)
Description

Returns true if the left is not equal to the right, otherwise returns false. left and right must result in the same fundamental type.

Arguments
NameType
left expr
right expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where bin age is not stored as an integer (bin type differs from AS_BYTES_INTEGER / ParticleType.INTEGER).

// import com.aerospike.client.command.ParticleType;
Expression exp = Exp.build(
Exp.ne(Exp.binType("age"), Exp.val(ParticleType.INTEGER)));
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?