Logic
Aerospike logic expressions allow you to apply logical operators to boolean expressions, returning a boolean result.
This guide covers operators like and, or, not, and exclusive for combining or evaluating conditions within queries. Code examples show how to use these expressions to simplify complex logic and improve query performance.
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  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 only one of the following criteria is true: the value in bin ‘hand’ is ‘hook’, the value in bin ‘leg’ is ‘peg’, or the value bin ‘pet’ is ‘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"))));not(arg)Returns true if the ‘boolean_expr’ is false; otherwise, it returns false.
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 bin ‘country’ is either ‘US’ or ‘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"))));