Logic
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
Logic expressions combine Boolean subexpressions with and, or, not, and exclusive (Database 5.6.0 and later). Each evaluates to a Boolean, so they go wherever a Boolean is required: a record filter on a single-record, batch, scan or query command, an XDR filter, a cond branch, and the filter contexts of path expressions. They occupy the same place as comparison expressions, and most often take comparisons as their operands.
and, or, and not follow trilean rules when an operand can be unknown — during the metadata-only phase of evaluation, for instance. or evaluates to true as soon as one operand is true, even when another is unknown. exclusive tests whether exactly one of its operands is true. For how true, false, and unknown interact otherwise, see the execution model and unknown.
Path expressions
and and or appear often inside path expression filter contexts such as allChildrenWithFilter and andFilter. See combining multiple filters in the path advanced guide.
The bookstore example on the path overview nests eq and lt on loop variables inside an and — typical of real document-style filters.
The Developer SDK’s AEL text syntax expresses the same logic inline, for example $.age > 21 and $.status == 'active'.
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.
Ops
and(arg0, arg1, ...)Returns false if any argument is false, true if every argument is true, and unknown otherwise (an argument is unknown and none is false).
| Name | Type | Description |
|---|---|---|
arg0 | boolean | First condition. |
arg1 | boolean | Second condition. |
... | boolean | Any further conditions. |
boolean Find records that have a stored user key and that key is an integer less than 1000 (metadata + key comparison). For the same combinator on nested bins inside path filters, see the bookstore example.
String exp = "$.keyExists() and $.key() < 1000";exp = "$.keyExists() and $.key() < 1000"use aerospike::expressions::{and, int_val, key, key_exists, lt, ExpType};
let exp = and(vec![key_exists(), lt(key(ExpType::INT), int_val(1000))]);Expression exp = Exp.Build( Exp.And( Exp.KeyExists(), Exp.LT(Exp.Key(Exp.Type.INT), Exp.Val(1000))));// Requires: import as "github.com/aerospike/aerospike-client-go/v8"exp := as.ExpAnd( as.ExpKeyExists(), as.ExpLess(as.ExpKey(as.ExpTypeINT), as.ExpIntVal(1000)))const exp = Aerospike.exp
const filterExp = exp.and( exp.keyExist(), exp.lt(exp.keyInt(), exp.int(1000)))as_exp_build(predexp, as_exp_and(as_exp_key_exist(), as_exp_cmp_lt(as_exp_key_int(), as_exp_int(1000))));Expression exp = Exp.build( Exp.and( Exp.keyExists(), Exp.lt(Exp.key(Exp.Type.INT), Exp.val(1000))));from aerospike_helpers.expressions import And, KeyExists, KeyInt, LT
exp = And(KeyExists(), LT(KeyInt(), 1000)).compile()exclusive(arg0, arg1, ...)Returns true if exactly one argument is true, and false if none or more than one is. Arguments are evaluated in order: an unknown argument makes the result unknown, unless two arguments before it are already true. Useful for testing whether several conditions are mutually exclusive.
| Name | Type | Description |
|---|---|---|
arg0 | boolean | First condition. |
arg1 | boolean | Second condition. |
... | boolean | Any further conditions. |
boolean Find records where exactly one of these is true: string bin hand is hook, leg is peg, or pet is parrot. (Illustrates mutual-exclusion checks on independent bins—not nested path logic.)
String exp = "exclusive($.hand == 'hook', $.leg == 'peg', $.pet == 'parrot')";exp = "exclusive($.hand == 'hook', $.leg == 'peg', $.pet == 'parrot')"use aerospike::expressions::{eq, exclusive, string_bin, string_val};
let exp = exclusive(vec![ eq(string_bin("hand".into()), string_val("hook".into())), eq(string_bin("leg".into()), string_val("peg".into())), eq(string_bin("pet".into()), string_val("parrot".into())),]);Expression exp = Exp.Build( Exp.Exclusive( Exp.EQ(Exp.StringBin("hand"), Exp.Val("hook")), Exp.EQ(Exp.StringBin("leg"), Exp.Val("peg")), Exp.EQ(Exp.StringBin("pet"), Exp.Val("parrot"))));// Requires: import as "github.com/aerospike/aerospike-client-go/v8"exp := as.ExpExclusive( as.ExpEq(as.ExpStringBin("hand"), as.ExpStringVal("hook")), as.ExpEq(as.ExpStringBin("leg"), as.ExpStringVal("peg")), as.ExpEq(as.ExpStringBin("pet"), as.ExpStringVal("parrot")))const exp = Aerospike.exp
const filterExp = exp.exclusive( exp.eq(exp.binStr('hand'), exp.str('hook')), exp.eq(exp.binStr('leg'), exp.str('peg')), exp.eq(exp.binStr('pet'), exp.str('parrot')))as_exp_build(predexp, as_exp_exclusive( as_exp_cmp_eq(as_exp_bin_str("hand"), as_exp_str("hook")), as_exp_cmp_eq(as_exp_bin_str("leg"), as_exp_str("peg")), as_exp_cmp_eq( as_exp_bin_str("pet"), as_exp_str("parrot"))));Expression exp = Exp.build( Exp.exclusive( Exp.eq(Exp.stringBin("hand"), Exp.val("hook")), Exp.eq(Exp.stringBin("leg"), Exp.val("peg")), Exp.eq(Exp.stringBin("pet"), Exp.val("parrot"))));from aerospike_helpers.expressions import Eq, Exclusive, StrBin
exp = Exclusive( Eq(StrBin("hand"), "hook"), Eq(StrBin("leg"), "peg"), Eq(StrBin("pet"), "parrot"),).compile()not(arg)Returns true if arg is false, false if arg is true, and unknown if arg is unknown.
| Name | Type | Description |
|---|---|---|
arg | boolean | Condition to negate. |
boolean Find records that do not have the primary key stored in record metadata (keyExists is false).
String exp = "not($.keyExists())";exp = "not($.keyExists())"use aerospike::expressions::{key_exists, not};
let exp = not(key_exists());Expression exp = Exp.Build(Exp.Not(Exp.KeyExists()));// Requires: import as "github.com/aerospike/aerospike-client-go/v8"exp := as.ExpNot(as.ExpKeyExists())const exp = Aerospike.exp
const filterExp = exp.not(exp.keyExist())as_exp_build(predexp, as_exp_not(as_exp_key_exist()));Expression exp = Exp.build(Exp.not(Exp.keyExists()));from aerospike_helpers.expressions import KeyExists, Not
exp = Not(KeyExists()).compile()or(arg0, arg1, ...)Returns true if any argument is true, false if every argument is false, and unknown otherwise (an argument is unknown and none is true).
| Name | Type | Description |
|---|---|---|
arg0 | boolean | First condition. |
arg1 | boolean | Second condition. |
... | boolean | Any further conditions. |
boolean Find records where string bin country is either US or CA (same “one of several string values” idea as the expression index tutorial, which uses Or / Eq for target countries in Python).
String exp = "$.country == 'US' or $.country == 'CA'";exp = "$.country == 'US' or $.country == 'CA'"use aerospike::expressions::{eq, or, string_bin, string_val};
let exp = or(vec![ eq(string_bin("country".into()), string_val("US".into())), eq(string_bin("country".into()), string_val("CA".into())),]);Expression exp = Exp.Build( Exp.Or( Exp.EQ(Exp.StringBin("country"), Exp.Val("US")), Exp.EQ(Exp.StringBin("country"), Exp.Val("CA"))));// Requires: import as "github.com/aerospike/aerospike-client-go/v8"exp := as.ExpOr( as.ExpEq(as.ExpStringBin("country"), as.ExpStringVal("US")), as.ExpEq(as.ExpStringBin("country"), as.ExpStringVal("CA")))const exp = Aerospike.exp
const filterExp = exp.or( exp.eq(exp.binStr('country'), exp.str('US')), exp.eq(exp.binStr('country'), exp.str('CA')))as_exp_build(predexp, as_exp_or( as_exp_cmp_eq(as_exp_bin_str("country"), as_exp_str("US")), as_exp_cmp_eq( as_exp_bin_str("country"), as_exp_str("CA"))));Expression exp = Exp.build( Exp.or( Exp.eq(Exp.stringBin("country"), Exp.val("US")), Exp.eq(Exp.stringBin("country"), Exp.val("CA"))));from aerospike_helpers.expressions import Eq, Or, StrBin
exp = Or( Eq(StrBin("country"), "US"), Eq(StrBin("country"), "CA"),).compile()