Skip to content
Webinar - July 10: Cut Infra Costs by 80% with Smarter DRAM, NVMe & Cloud Storage StrategyRegister now

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

and(arg0, arg1, ...)
Description

Returns false if any ‘boolean_expr’ is false; otherwise, it returns true.

Arguments
NameType
arg0 boolean_expr
arg1 boolean_expr
... boolean_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records have a key and the key is less than 1000.

as_exp_build(predexp,
as_exp_and(as_exp_key_exists(),
as_exp_cmp_lt(as_exp_int_key(), as_exp_int(1000))));

exclusive

exclusive(arg0, arg1, ...)
Description

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.

Arguments
NameType
arg0 boolean_expr
arg1 boolean_expr
... boolean_expr
Returns
boolean_value
Introduced
5.6.0
Example

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"))));

not

not(arg)
Description

Returns true if the ‘boolean_expr’ is false; otherwise, it returns false.

Arguments
NameType
arg boolean_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find where records that do not have a stored key.

as_exp_build(predexp, as_exp_not(as_exp_key_exists()));

or

or(arg0, arg1, ...)
Description

Returns true if any ‘boolean_expr’ is true; otherwise, it returns false.

Arguments
NameType
arg0 boolean_expr
arg1 boolean_expr
... boolean_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

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"))));
Feedback