Logic
Logic expressions combine boolean subexpressions with and, or, not, and exclusive (needs server 5.6.0+). The result is boolean and is used in the same places as comparison expressions: record filters, query and batch FilterExpression, XDR filters, and other APIs that accept filter expressions.
and / or / not follow trilean rules when inputs can be unknown (for example during the metadata-only phase of evaluation). exclusive tests whether exactly one of its boolean arguments is true. For how true, false, and unknown interact, see the execution model on the expressions overview.
Path expressions
and and or appear frequently 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 shows Exp.and with nested eq and lt on loop variables—typical of real document-style filters.
Ops
and(arg0, arg1, ...)Returns false if any ‘boolean_expr’ is false; otherwise, it returns true.
| Name | Type |
|---|---|
arg0 | boolean_expr |
arg1 | boolean_expr |
... | boolean_expr |
boolean_value 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.
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()as_exp_build(predexp, as_exp_and(as_exp_key_exist(), as_exp_cmp_lt(as_exp_key_int(), as_exp_int(1000))));// Import path matches the Go client examples elsewhere on this doc site (/v6).// If you use the latest client line, switch to .../aerospike-client-go/v8 (API names unchanged).// Requires: import as "github.com/aerospike/aerospike-client-go/v6"exp := as.ExpAnd( as.ExpKeyExists(), as.ExpLess(as.ExpKey(as.ExpTypeINT), as.ExpIntVal(1000)))Expression exp = Exp.Build( Exp.And( Exp.KeyExists(), Exp.LT(Exp.Key(Exp.Type.INT), Exp.Val(1000))));const exp = Aerospike.exp
const filterExp = exp.and( exp.keyExist(), exp.lt(exp.keyInt(), exp.int(1000)))exclusive(arg0, arg1, ...)Returns true if exactly one ‘boolean_expr’ is true; otherwise, it returns false. This expression is helpful for testing whether multiple expressions are mutually exclusive.
| Name | Type |
|---|---|
arg0 | boolean_expr |
arg1 | boolean_expr |
... | boolean_expr |
boolean_value 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.)
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()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"))));// Import path matches the Go client examples elsewhere on this doc site (/v6).// If you use the latest client line, switch to .../aerospike-client-go/v8 (API names unchanged).// Requires: import as "github.com/aerospike/aerospike-client-go/v6"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")))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"))));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')))not(arg)Returns true if the ‘boolean_expr’ is false; otherwise, it returns false.
| Name | Type |
|---|---|
arg | boolean_expr |
boolean_value Find records that do not have the primary key stored in record metadata (keyExists is false).
Expression exp = Exp.build(Exp.not(Exp.keyExists()));from aerospike_helpers.expressions import KeyExists, Not
exp = Not(KeyExists()).compile()as_exp_build(predexp, as_exp_not(as_exp_key_exist()));// Import path matches the Go client examples elsewhere on this doc site (/v6).// If you use the latest client line, switch to .../aerospike-client-go/v8 (API names unchanged).// Requires: import as "github.com/aerospike/aerospike-client-go/v6"exp := as.ExpNot(as.ExpKeyExists())Expression exp = Exp.Build(Exp.Not(Exp.KeyExists()));const exp = Aerospike.exp
const filterExp = exp.not(exp.keyExist())or(arg0, arg1, ...)Returns true if any ‘boolean_expr’ is true; otherwise, it returns false.
| Name | Type |
|---|---|
arg0 | boolean_expr |
arg1 | boolean_expr |
... | boolean_expr |
boolean_value 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).
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()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"))));// Import path matches the Go client examples elsewhere on this doc site (/v6).// If you use the latest client line, switch to .../aerospike-client-go/v8 (API names unchanged).// Requires: import as "github.com/aerospike/aerospike-client-go/v6"exp := as.ExpOr( as.ExpEq(as.ExpStringBin("country"), as.ExpStringVal("US")), as.ExpEq(as.ExpStringBin("country"), as.ExpStringVal("CA")))Expression exp = Exp.Build( Exp.Or( Exp.EQ(Exp.StringBin("country"), Exp.Val("US")), Exp.EQ(Exp.StringBin("country"), Exp.Val("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')))