Skip to content

Comparison

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

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.

Both operands must be the same type — two integers, or two strings, but never an integer and a float. A mismatch fails the command with error 4 (parameter error), rather than evaluating to false. A bin that holds a different type from the one its reader expects is another matter: the reader evaluates to unknown, so as a filter the record is rejected like any other non-match. GeoJSON and HLL cannot be compared at all; use cmp_geo for GeoJSON. See Types on the expressions overview.

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 (Database 8.1.2 and later). The examples use bins and thresholds aligned with the bookstore scenario on the path expressions page.

The Developer SDK’s AEL text syntax expresses the same comparisons inline, for example $.age >= 21.

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.

String values

eq, ne, gt, ge, lt, and le compare String values by UTF-8 bytes. The six String search operations in Database 8.2.0 treat canonically equivalent spellings as equal, so their results can differ from comparison operators. See Compare String values.

Map values

As of Database 8.2.0, eq, ne, gt, ge, lt, and le compare Maps by content, regardless of subtype. Two Maps with the same elements are equal whether they are Unordered, K-ordered, or KV-ordered, including Maps nested in a List or another Map. See Ordering for how one Map orders against another.

Before Database 8.2.0, a comparison evaluates to unknown when either operand is an Unordered Map or contains one, so a record filter built on it matches no records.

Ops

cmp_geo

cmp_geo(left, right)
Description

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

Arguments
NameTypeDescription
leftgeojson

GeoJSON point or region. Any expression that evaluates to a GeoJSON value.

rightgeojson

The GeoJSON value to test left against. One operand must be a point and the other a region; two points, or two regions, always return false.

Returns
boolean
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 exp = "geoCompare("
+ "geoJson('{\"type\":\"Point\",\"coordinates\":[-122.4,37.8]}'), $.region)";

cmp_regex

deprecated
cmp_regex(options_value, regex_string, string)
Description

Returns true if the regex_string matches the string, otherwise returns false. Uses POSIX regex and is not Unicode-compatible. Superseded by string_regex_compare.

Arguments
NameTypeDescription
options_valueinteger literal

POSIX regcomp flags, combined with bitwise OR, or 0 for none: 1 extended syntax, 2 case-insensitive, 4 newline-sensitive matching, 8 no effect. Pass the numbers — most clients name 4 NOSUB and 8 NEWLINE, the reverse of what the server applies.

regex_stringstring literal

POSIX regular expression to match. Compiled once when the expression is built, so it cannot be computed from a bin.

stringstring

String bin to match against, or any expression that evaluates to a string.

Returns
boolean
Introduced
5.2.0.4
Example

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

use aerospike::expressions::{regex_compare, string_bin};
use aerospike::RegexFlag;
let exp = regex_compare(
"^555.*".into(),
RegexFlag::NONE as i64,
string_bin("phone_num".into()));

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.

When both operands are strings, eq tests UTF-8 byte equality. A precomposed é (U+00E9) and an e followed by a combining acute accent (U+0301) are not equal. The string search operations treat those spellings as the same text. See Compare String values.

As of Database 8.2.0, eq compares Maps by content regardless of subtype. Two Maps with the same elements are equal whether they are Unordered, K-ordered, or KV-ordered, including Maps nested in a List or another Map. Before Database 8.2.0, eq returns unknown when either operand is an Unordered Map or contains one. See Map values.

Arguments
NameTypeDescription
leftany

Left operand. Any expression that evaluates to an integer, float, string, blob, boolean, list, or map. GeoJSON and HLL cannot be compared this way; for GeoJSON use cmp_geo.

rightany

Right operand. Must evaluate to the same type as left.

Returns
boolean
Introduced
5.2.0.4
Example

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

String exp = "$.category == '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
NameTypeDescription
leftany

Left operand. Any expression that evaluates to an integer, float, string, blob, boolean, list, or map. GeoJSON and HLL cannot be compared this way; for GeoJSON use cmp_geo.

rightany

Right operand. Must evaluate to the same type as left.

Returns
boolean
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.

String exp = "$.quantity >= 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
NameTypeDescription
leftany

Left operand. Any expression that evaluates to an integer, float, string, blob, boolean, list, or map. GeoJSON and HLL cannot be compared this way; for GeoJSON use cmp_geo.

rightany

Right operand. Must evaluate to the same type as left.

Returns
boolean
Introduced
5.2.0.4
Example

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

String exp = "$.ttl() > 365 * 24 * 3600";

in_list

in_list(value, list)
Description

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

Arguments
NameTypeDescription
valueany

Value to look for. Matching is by type as well as by value, so an integer never matches a float and a boolean never matches an integer.

listlist

List to search. A list bin, a list literal, or any expression that evaluates to a list; its elements need not all be of one type.

Returns
boolean
Introduced
8.1.2
Example

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

String exp = "$.color in ['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
NameTypeDescription
leftany

Left operand. Any expression that evaluates to an integer, float, string, blob, boolean, list, or map. GeoJSON and HLL cannot be compared this way; for GeoJSON use cmp_geo.

rightany

Right operand. Must evaluate to the same type as left.

Returns
boolean
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.

String exp = "$.quantity <= 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
NameTypeDescription
leftany

Left operand. Any expression that evaluates to an integer, float, string, blob, boolean, list, or map. GeoJSON and HLL cannot be compared this way; for GeoJSON use cmp_geo.

rightany

Right operand. Must evaluate to the same type as left.

Returns
boolean
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.

String exp = "$.price < 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
NameTypeDescription
leftany

Left operand. Any expression that evaluates to an integer, float, string, blob, boolean, list, or map. GeoJSON and HLL cannot be compared this way; for GeoJSON use cmp_geo.

rightany

Right operand. Must evaluate to the same type as left.

Returns
boolean
Introduced
5.2.0.4
Example

Find records where bin age does not hold an integer.

String exp = "$.age.type() != INT";