---
title: "HyperLogLog expressions"
description: "Aerospike HyperLogLog (HLL) expressions guide covering read and modify operations with multi-language examples."
---

# HyperLogLog expressions

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

HyperLogLog (HLL) expressions run the same read and modify operations as the [HLL data type](https://aerospike.com/docs/develop/data-types/hll) — estimated cardinality, union, intersection, similarity, describe, may-contain — inside an [expression](https://aerospike.com/docs/develop/expressions/) tree rather than against a named bin.

Read expressions (`hll_get_count`, `hll_get_union`, …) evaluate to an integer, float, list, or HLL value. That makes them **projection**: they shape what a command returns for each record, in [`operate`](https://aerospike.com/docs/develop/learn/bin-operations/), in a [batch](https://aerospike.com/docs/develop/learn/batch/), and in a [query](https://aerospike.com/docs/develop/learn/queries/projection). Wrap one in [comparison](https://aerospike.com/docs/develop/expressions/comparison) or [logic](https://aerospike.com/docs/develop/expressions/logic) to get the Boolean a record filter needs.

Modify expressions (`hll_add`, `hll_update`, …) evaluate to a new HLL value and leave the record untouched. Storing that value takes a write operation expression; see [Operations and expressions](https://aerospike.com/docs/develop/learn/operations-and-expressions) for how the two APIs differ.

An HLL operand is a bin, read with [`bin_hll`](https://aerospike.com/docs/develop/expressions/storage#bin_hll), or any expression that evaluates to an HLL. Reading stored data can evaluate to `unknown`; see [Unknown results](https://aerospike.com/docs/develop/expressions#unknown-results).

The Developer SDK’s [AEL](https://aerospike.com/docs/develop/client/sdk/concepts/ael/reference) text syntax exposes the same HLL read functions as path methods, for example `$.h.hllCount() > 1000000`.

## Composing expressions

An expression evaluates to a value, and that value is what the next expression operates on — see [Expressions compose](https://aerospike.com/docs/develop/expressions#expressions-compose).

[`hll_add`](#hll_add) is the clearest case: it evaluates to an HLL value, and [`hll_get_count`](#hll_get_count) counts that value, neither of them touching the record. Most HLL operations take a nested expression as their `bin` operand the same way, including the union and intersection reads.

[`hll_describe`](#hll_describe) composes in the other direction. It evaluates to a two-element list, so pair it with a [list](https://aerospike.com/docs/develop/expressions/list) read such as [`list_get_by_index`](https://aerospike.com/docs/develop/expressions/list#list_get_by_index) to pull out the index bit count or the MinHash bit count on its own.

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](https://aerospike.com/docs/develop/client/sdk/concepts/ael/reference) for AEL grammar.

## Modify

#### `hll_add`

```python
hll_add(policy, items, index_bit_count, bin)
```

Description: Returns the HLL that `bin` evaluates to, with `items` added. It cannot bring a sketch into existence: if `bin` names a record bin that does not exist, the expression returns `AS_ERR_OP_NOT_APPLICABLE`.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `HLL policy` | 
Write policy for the transform. Supplied by your client as an HLL policy object.

 |
| `items` | `list` | 

Elements to add to the sketch.

 |
| `index_bit_count` | `integer` | 

Number of index bits, between 4 and 16. It has no effect here: it sizes a sketch at creation, and this expression cannot create one. Use [`hll_init`](#hll_init) to build a sketch of a given size.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `hll`

Introduced: 5.2.0.4

Example: Add string ids from list bin `new_user_ids` into the existing `visitors` sketch, then require a non-zero estimated count.

-   [Java SDK](#tab-panel-1354)
-   [Python SDK](#tab-panel-1355)
-   [Rust](#tab-panel-1356)
-   [C#](#tab-panel-1357)
-   [Go](#tab-panel-1358)
-   [Node.js](#tab-panel-1359)
-   [C](#tab-panel-1360)
-   [Java](#tab-panel-1361)
-   [Python](#tab-panel-1362)

```java
String exp = "$.visitors.hllAdd($.new_user_ids, indexBits: 10).hllCount() > 0";
```

```python
exp = "$.visitors.hllAdd($.new_user_ids, indexBits: 10).hllCount() > 0"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{gt, hll_bin, int_val, list_bin};

use aerospike::operations::hll::HLLPolicy;

let exp = gt(

    hll_exp::get_count(

        hll_exp::add_with_index(

            HLLPolicy::default(),

            list_bin("new_user_ids".into()),

            int_val(10),

            hll_bin("visitors".into()))),

    int_val(0));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(

    HLLExp.GetCount(

      HLLExp.Add(

        HLLPolicy.Default,

        Exp.ListBin("new_user_ids"),

        Exp.Val(10),

        Exp.HLLBin("visitors"))),

    Exp.Val(0)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

added := as.ExpHLLAddWithIndex(

  as.DefaultHLLPolicy(),

  as.ExpListBin("new_user_ids"),

  as.ExpIntVal(10),

  as.ExpHLLBin("visitors"),

)

exp := as.ExpGreater(as.ExpHLLGetCount(added), as.ExpIntVal(0))
```

```javascript
const exp = Aerospike.exp

const added = exp.hll.add(

  exp.binHll('visitors'),

  10,

  exp.binList('new_user_ids'),

  null,

)

const filterExp = exp.gt(exp.hll.getCount(added), exp.int(0))
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_hll_get_count(

      as_exp_hll_add(

        NULL,

        as_exp_bin_list("new_user_ids"),

        10,

        as_exp_bin_hll("visitors"))),

    as_exp_int(0)));
```

```java
import com.aerospike.client.operation.HLLPolicy;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.gt(

    HLLExp.getCount(

      HLLExp.add(

        HLLPolicy.Default,

        Exp.listBin("new_user_ids"),

        Exp.val(10),

        Exp.hllBin("visitors"))),

    Exp.val(0)));
```

```python
from aerospike_helpers.expressions import GT, HLLBin, ListBin

from aerospike_helpers.expressions.hll import HLLAdd, HLLGetCount

added = HLLAdd(None, ListBin("new_user_ids"), 10, None, HLLBin("visitors"))

exp = GT(HLLGetCount(added), 0).compile()
```

---

#### `hll_add_mh`

```python
hll_add_mh(policy, items, index_bit_count, minhash_bit_count, bin)
```

Description: Returns the HLL that `bin` evaluates to, with `items` added. Like `hll_add`, it requires the operand to already be an HLL. MinHash bits make `hll_get_intersect_count` and `hll_get_similarity` reliable, but they belong to the sketch being operated on — set them where it is created, with the Operate API `add_mh` or `init`.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `HLL policy` | 
Write policy for the transform. Supplied by your client as an HLL policy object.

 |
| `items` | `list` | 

Elements to add to the sketch.

 |
| `index_bit_count` | `integer` | 

Number of index bits, between 4 and 16. It has no effect here: it sizes a sketch at creation, and this expression cannot create one. Use [`hll_init`](#hll_init) to build a sketch of a given size.

 |
| `minhash_bit_count` | `integer` | 

Number of MinHash bits, between 4 and 51, summing with the index bits to 64 or fewer. Like `index_bit_count` it has no effect here; see [`hll_init`](#hll_init).

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `hll`

Introduced: 5.2.0.4

Example: Same as `hll_add`, taking both bit counts. Neither has an effect on an existing sketch.

-   [Java SDK](#tab-panel-1363)
-   [Python SDK](#tab-panel-1364)
-   [Rust](#tab-panel-1365)
-   [C#](#tab-panel-1366)
-   [Go](#tab-panel-1367)
-   [Node.js](#tab-panel-1368)
-   [C](#tab-panel-1369)
-   [Java](#tab-panel-1370)
-   [Python](#tab-panel-1371)

```java
String exp = "$.visitors.hllAdd($.new_user_ids, indexBits: 10, minHashBits: 20)"

    + ".hllCount() > 0";
```

```python
exp = ("$.visitors.hllAdd($.new_user_ids, indexBits: 10, minHashBits: 20)"

       ".hllCount() > 0")
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{gt, hll_bin, int_val, list_bin};

use aerospike::operations::hll::HLLPolicy;

let exp = gt(

    hll_exp::get_count(

        hll_exp::add_with_index_and_min_hash(

            HLLPolicy::default(),

            list_bin("new_user_ids".into()),

            int_val(10),

            int_val(20),

            hll_bin("visitors".into()))),

    int_val(0));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(

    HLLExp.GetCount(

      HLLExp.Add(

        HLLPolicy.Default,

        Exp.ListBin("new_user_ids"),

        Exp.Val(10),

        Exp.Val(20),

        Exp.HLLBin("visitors"))),

    Exp.Val(0)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

added := as.ExpHLLAddWithIndexAndMinHash(

  as.DefaultHLLPolicy(),

  as.ExpListBin("new_user_ids"),

  as.ExpIntVal(10),

  as.ExpIntVal(20),

  as.ExpHLLBin("visitors"),

)

exp := as.ExpGreater(as.ExpHLLGetCount(added), as.ExpIntVal(0))
```

```javascript
const exp = Aerospike.exp

const added = exp.hll.addMH(

  exp.binHll('visitors'),

  20,

  10,

  exp.binList('new_user_ids'),

  null,

)

const filterExp = exp.gt(exp.hll.getCount(added), exp.int(0))
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_hll_get_count(

      as_exp_hll_add_mh(

        NULL,

        as_exp_bin_list("new_user_ids"),

        10,

        20,

        as_exp_bin_hll("visitors"))),

    as_exp_int(0)));
```

```java
import com.aerospike.client.operation.HLLPolicy;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.gt(

    HLLExp.getCount(

      HLLExp.add(

        HLLPolicy.Default,

        Exp.listBin("new_user_ids"),

        Exp.val(10),

        Exp.val(20),

        Exp.hllBin("visitors"))),

    Exp.val(0)));
```

```python
from aerospike_helpers.expressions import GT, HLLBin, ListBin

from aerospike_helpers.expressions.hll import HLLAdd, HLLGetCount

added = HLLAdd(None, ListBin("new_user_ids"), 10, 20, HLLBin("visitors"))

exp = GT(HLLGetCount(added), 0).compile()
```

---

#### `hll_init`

```python
hll_init(policy, index_bit_count[, minhash_bit_count], bin)
```

Description: Returns a new, empty HLL sized by `index_bit_count` and, where given, `minhash_bit_count`. Unlike [`hll_add`](#hll_add), the bit counts take effect here, because this expression is the one that builds the sketch. The record is not touched: storing the result takes a write operation expression.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `HLL policy` | 
Write policy for the transform. Supplied by your client as an HLL policy object.

 |
| `index_bit_count` | `integer` | 

Number of index bits, between 4 and 16. More bits give a more accurate estimate and a larger sketch.

 |
| `minhash_bit_count` | `integer` | 

Number of MinHash bits, between 4 and 51, summing with the index bits to 64 or fewer. MinHash bits improve intersection and similarity estimates. Optional; omit them for a plain HyperLogLog.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `hll`

Introduced: 5.2.0.4

Example: Size a fresh sketch at `index_bit_count` 12 and confirm it is empty. Because `hll_init` discards whatever the operand held, the count is `0` however many values `visitors` contains.

-   [Java SDK](#tab-panel-1372)
-   [Python SDK](#tab-panel-1373)
-   [Rust](#tab-panel-1374)
-   [C#](#tab-panel-1375)
-   [Go](#tab-panel-1376)
-   [Node.js](#tab-panel-1377)
-   [C](#tab-panel-1378)
-   [Java](#tab-panel-1379)
-   [Python](#tab-panel-1380)

```java
String exp = "$.visitors.hllInit(indexBits: 12).hllCount() == 0";
```

```python
exp = "$.visitors.hllInit(indexBits: 12).hllCount() == 0"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{eq, hll_bin, int_val};

use aerospike::operations::hll::HLLPolicy;

let exp = eq(

    hll_exp::get_count(

        hll_exp::init(HLLPolicy::default(), int_val(12), hll_bin("visitors".into()))),

    int_val(0));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    HLLExp.GetCount(

      HLLExp.Init(HLLPolicy.Default, Exp.Val(12), Exp.HLLBin("visitors"))),

    Exp.Val(0)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpHLLGetCount(

    as.ExpHLLInit(as.DefaultHLLPolicy(), as.ExpIntVal(12),

      as.ExpHLLBin("visitors"))),

  as.ExpIntVal(0))
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.hll.getCount(

    exp.hll.init(exp.binHll('visitors'), 12)),

  exp.int(0))
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_hll_get_count(

      as_exp_hll_init(NULL, 12, as_exp_bin_hll("visitors"))),

    as_exp_int(0)));
```

```java
import com.aerospike.client.operation.HLLPolicy;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.eq(

    HLLExp.getCount(

      HLLExp.init(HLLPolicy.Default, Exp.val(12), Exp.hllBin("visitors"))),

    Exp.val(0)));
```

```python
from aerospike_helpers.expressions import Eq, HLLBin

from aerospike_helpers.expressions.hll import HLLGetCount, HLLInit

fresh = HLLInit(None, 12, None, HLLBin("visitors"))

exp = Eq(HLLGetCount(fresh), 0).compile()
```

---

#### `hll_update`

```python
hll_update(policy, items, bin)
```

Description: Returns the HLL that `bin` evaluates to, with `items` added. It differs from `hll_add` only in taking no bit counts.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `policy` | `HLL policy` | 
Write policy for the transform. Supplied by your client as an HLL policy object.

 |
| `items` | `list` | 

Elements to add to the sketch.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `hll`

Introduced: 5.2.0.4

Example: Add values from list bin `new_user_ids` to an **existing** HLL `visitors` (no index/minhash creation path).

-   [Java SDK](#tab-panel-1381)
-   [Python SDK](#tab-panel-1382)
-   [Rust](#tab-panel-1383)
-   [C#](#tab-panel-1384)
-   [Go](#tab-panel-1385)
-   [Node.js](#tab-panel-1386)
-   [C](#tab-panel-1387)
-   [Java](#tab-panel-1388)
-   [Python](#tab-panel-1389)

```java
String exp = "$.visitors.hllAdd($.new_user_ids).hllCount() > 0";
```

```python
exp = "$.visitors.hllAdd($.new_user_ids).hllCount() > 0"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{gt, hll_bin, int_val, list_bin};

use aerospike::operations::hll::HLLPolicy;

let exp = gt(

    hll_exp::get_count(

        hll_exp::add(

            HLLPolicy::default(),

            list_bin("new_user_ids".into()),

            hll_bin("visitors".into()))),

    int_val(0));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(

    HLLExp.GetCount(

      HLLExp.Add(

        HLLPolicy.Default,

        Exp.ListBin("new_user_ids"),

        Exp.HLLBin("visitors"))),

    Exp.Val(0)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

updated := as.ExpHLLAdd(

  as.DefaultHLLPolicy(),

  as.ExpListBin("new_user_ids"),

  as.ExpHLLBin("visitors"),

)

exp := as.ExpGreater(as.ExpHLLGetCount(updated), as.ExpIntVal(0))
```

```javascript
const exp = Aerospike.exp

const updated = exp.hll.update(

  exp.binHll('visitors'),

  exp.binList('new_user_ids'),

  null,

)

const filterExp = exp.gt(exp.hll.getCount(updated), exp.int(0))
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_hll_get_count(

      as_exp_hll_update(

        NULL,

        as_exp_bin_list("new_user_ids"),

        as_exp_bin_hll("visitors"))),

    as_exp_int(0)));
```

```java
import com.aerospike.client.operation.HLLPolicy;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.gt(

    HLLExp.getCount(

      HLLExp.add(

        HLLPolicy.Default,

        Exp.listBin("new_user_ids"),

        Exp.hllBin("visitors"))),

    Exp.val(0)));
```

```python
from aerospike_helpers.expressions import GT, HLLBin, ListBin

from aerospike_helpers.expressions.hll import HLLAdd, HLLGetCount

updated = HLLAdd(None, ListBin("new_user_ids"), None, None, HLLBin("visitors"))

exp = GT(HLLGetCount(updated), 0).compile()
```

---

## Read

#### `hll_describe`

```python
hll_describe(bin)
```

Description: Returns a two-element list holding the HLL’s index bit count and MinHash bit count. Pair it with a list read such as [`list_get_by_index`](https://aerospike.com/docs/develop/expressions/list#list_get_by_index) to pull out one of the two.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bin` | `hll` | 
HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `list`

Introduced: 5.2.0.4

Example: The HLL’s index bit count (describe result index `0`) is fewer than 16; uses a [list](https://aerospike.com/docs/develop/expressions/list/) read on the describe list.

-   [Java SDK](#tab-panel-1399)
-   [Python SDK](#tab-panel-1400)
-   [Rust](#tab-panel-1401)
-   [C#](#tab-panel-1402)
-   [Go](#tab-panel-1403)
-   [Node.js](#tab-panel-1404)
-   [C](#tab-panel-1405)
-   [Java](#tab-panel-1406)
-   [Python](#tab-panel-1407)

```java
String exp = "($.visitors.hllDescribe()).[0] < 16";
```

```python
exp = "($.visitors.hllDescribe()).[0] < 16"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::lists as list_exp;

use aerospike::expressions::{ExpType, hll_bin, int_val, lt};

use aerospike::ListReturnType;

let exp = lt(

    list_exp::get_by_index(

        ListReturnType::Values,

        ExpType::INT,

        int_val(0),

        hll_exp::describe(hll_bin("visitors".into())),

        &[]),

    int_val(16));
```

```csharp
Expression exp = Exp.Build(

  Exp.LT(

    ListExp.GetByIndex(

      ListReturnType.VALUE,

      Exp.Type.INT,

      Exp.Val(0),

      HLLExp.Describe(Exp.HLLBin("visitors"))),

    Exp.Val(16)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpLess(

  as.ExpListGetByIndex(

    as.ListReturnTypeValue,

    as.ExpTypeINT,

    as.ExpIntVal(0),

    as.ExpHLLDescribe(as.ExpHLLBin("visitors")),

  ),

  as.ExpIntVal(16),

)
```

```javascript
const exp = Aerospike.exp

const lists = Aerospike.lists

const filterExp = exp.lt(

  exp.lists.getByIndex(

    exp.hll.describe(exp.binHll('visitors')),

    exp.int(0),

    exp.type.INT,

    lists.returnType.VALUE,

  ),

  exp.int(16),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_lt(

    as_exp_list_get_by_index(

      NULL,

      AS_LIST_RETURN_VALUE,

      AS_EXP_TYPE_INT,

      as_exp_int(0),

      as_exp_hll_describe(as_exp_bin_hll("visitors"))),

    as_exp_int(16)));
```

```java
import com.aerospike.client.cdt.ListReturnType;

import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

import com.aerospike.client.exp.ListExp;

Expression exp = Exp.build(

  Exp.lt(

    ListExp.getByIndex(

      ListReturnType.VALUE,

      Exp.Type.INT,

      Exp.val(0),

      HLLExp.describe(Exp.hllBin("visitors"))),

    Exp.val(16)));
```

```python
import aerospike

from aerospike_helpers.expressions import HLLBin, LT

from aerospike_helpers.expressions.hll import HLLDescribe

from aerospike_helpers.expressions.list import ListGetByIndex

from aerospike_helpers.expressions.resources import ResultType

desc = HLLDescribe(HLLBin("visitors"))

exp = LT(

    ListGetByIndex(

        None,

        aerospike.LIST_RETURN_VALUE,

        ResultType.INTEGER,

        0,

        desc,

    ),

    16,

).compile()
```

---

#### `hll_get_count`

```python
hll_get_count(bin)
```

Description: Returns the estimated number of distinct elements in the HLL. The error depends on the index bit count the sketch was built with; see [Error bounds](https://aerospike.com/docs/develop/data-types/hll#error-bounds).

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `bin` | `hll` | 
HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Filter to records whose HLL `visitors` sketch estimates more than 100 unique ids.

-   [Java SDK](#tab-panel-1390)
-   [Python SDK](#tab-panel-1391)
-   [Rust](#tab-panel-1392)
-   [C#](#tab-panel-1393)
-   [Go](#tab-panel-1394)
-   [Node.js](#tab-panel-1395)
-   [C](#tab-panel-1396)
-   [Java](#tab-panel-1397)
-   [Python](#tab-panel-1398)

```java
String exp = "$.visitors.hllCount() > 100";
```

```python
exp = "$.visitors.hllCount() > 100"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{gt, hll_bin, int_val};

let exp = gt(hll_exp::get_count(hll_bin("visitors".into())), int_val(100));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(HLLExp.GetCount(Exp.HLLBin("visitors")), Exp.Val(100)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpGreater(

  as.ExpHLLGetCount(as.ExpHLLBin("visitors")),

  as.ExpIntVal(100),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.gt(

  exp.hll.getCount(exp.binHll('visitors')),

  exp.int(100),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_hll_get_count(as_exp_bin_hll("visitors")),

    as_exp_int(100)));
```

```java
import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.gt(HLLExp.getCount(Exp.hllBin("visitors")), Exp.val(100)));
```

```python
from aerospike_helpers.expressions import GT, HLLBin

from aerospike_helpers.expressions.hll import HLLGetCount

exp = GT(HLLGetCount(HLLBin("visitors")), 100).compile()
```

---

#### `hll_get_intersect_count`

```python
hll_get_intersect_count(hll_list, bin)
```

Description: Returns the estimated number of distinct elements common to `hll_list` and the HLL that `bin` evaluates to. Accuracy depends on MinHash bits: the estimate is stable when the sketches carry them and unstable when they do not. See [Error bounds](https://aerospike.com/docs/develop/data-types/hll#error-bounds).

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `hll_list` | `list` | 
HLLs to intersect with the operand.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Estimated intersection size between `cohort_a` and `visitors` is at least 50.

-   [Java SDK](#tab-panel-1408)
-   [Python SDK](#tab-panel-1409)
-   [Rust](#tab-panel-1410)
-   [C#](#tab-panel-1411)
-   [Go](#tab-panel-1412)
-   [Node.js](#tab-panel-1413)
-   [C](#tab-panel-1414)
-   [Java](#tab-panel-1415)
-   [Python](#tab-panel-1416)

```java
String exp = "$.visitors.hllIntersectCount($.cohort_a) >= 50";
```

```python
exp = "$.visitors.hllIntersectCount($.cohort_a) >= 50"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{ge, hll_bin, int_val};

let exp = ge(

    hll_exp::get_intersect_count(

        hll_bin("cohort_a".into()),

        hll_bin("visitors".into())),

    int_val(50));
```

```csharp
Expression exp = Exp.Build(

  Exp.GE(

    HLLExp.GetIntersectCount(Exp.HLLBin("cohort_a"), Exp.HLLBin("visitors")),

    Exp.Val(50)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpGreaterEq(

  as.ExpHLLGetIntersectCount(as.ExpHLLBin("cohort_a"), as.ExpHLLBin("visitors")),

  as.ExpIntVal(50),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.ge(

  exp.hll.getIntersectCount(

    exp.binHll('visitors'),

    exp.binHll('cohort_a'),

  ),

  exp.int(50),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_ge(

    as_exp_hll_get_intersect_count(

      as_exp_bin_hll("cohort_a"),

      as_exp_bin_hll("visitors")),

    as_exp_int(50)));
```

```java
import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.ge(

    HLLExp.getIntersectCount(Exp.hllBin("cohort_a"), Exp.hllBin("visitors")),

    Exp.val(50)));
```

```python
from aerospike_helpers.expressions import GE, HLLBin

from aerospike_helpers.expressions.hll import HLLGetIntersectCount

exp = GE(

    HLLGetIntersectCount(HLLBin("cohort_a"), HLLBin("visitors")),

    50,

).compile()
```

---

#### `hll_get_similarity`

```python
hll_get_similarity(hll_list, bin)
```

Description: Returns the estimated Jaccard index of `hll_list` and the HLL that `bin` evaluates to — the size of their intersection over the size of their union, from 0.0 for disjoint sets to 1.0 for identical ones. See [Error bounds](https://aerospike.com/docs/develop/data-types/hll#error-bounds).

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `hll_list` | `list` | 
HLLs to compare against the operand.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `float`

Introduced: 5.2.0.4

Example: Jaccard-style similarity between `cohort_a` and `visitors` is at least 0.5.

-   [Java SDK](#tab-panel-1417)
-   [Python SDK](#tab-panel-1418)
-   [Rust](#tab-panel-1419)
-   [C#](#tab-panel-1420)
-   [Go](#tab-panel-1421)
-   [Node.js](#tab-panel-1422)
-   [C](#tab-panel-1423)
-   [Java](#tab-panel-1424)
-   [Python](#tab-panel-1425)

```java
String exp = "$.visitors.hllSimilarity($.cohort_a) >= 0.5";
```

```python
exp = "$.visitors.hllSimilarity($.cohort_a) >= 0.5"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{float_val, ge, hll_bin};

let exp = ge(

    hll_exp::get_similarity(hll_bin("cohort_a".into()), hll_bin("visitors".into())),

    float_val(0.5));
```

```csharp
Expression exp = Exp.Build(

  Exp.GE(

    HLLExp.GetSimilarity(Exp.HLLBin("cohort_a"), Exp.HLLBin("visitors")),

    Exp.Val(0.5)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpGreaterEq(

  as.ExpHLLGetSimilarity(as.ExpHLLBin("cohort_a"), as.ExpHLLBin("visitors")),

  as.ExpFloatVal(0.5),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.ge(

  exp.hll.getSimilarity(

    exp.binHll('visitors'),

    exp.binHll('cohort_a'),

  ),

  exp.float(0.5),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_ge(

    as_exp_hll_get_similarity(

      as_exp_bin_hll("cohort_a"),

      as_exp_bin_hll("visitors")),

    as_exp_float(0.5)));
```

```java
import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.ge(

    HLLExp.getSimilarity(Exp.hllBin("cohort_a"), Exp.hllBin("visitors")),

    Exp.val(0.5)));
```

```python
from aerospike_helpers.expressions import GE, HLLBin

from aerospike_helpers.expressions.hll import HLLGetSimilarity

exp = GE(

    HLLGetSimilarity(HLLBin("cohort_a"), HLLBin("visitors")),

    0.5,

).compile()
```

---

#### `hll_get_union`

```python
hll_get_union(hll_list, bin)
```

Description: Returns an HLL representing the union of `hll_list` and the HLL that `bin` evaluates to.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `hll_list` | `list` | 
HLLs to union with the operand.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `hll`

Introduced: 5.2.0.4

Example: Union of HLL `cohort_a` with `visitors`, then require a non-empty estimate (via `hll_get_count` on the union result).

-   [Java SDK](#tab-panel-1426)
-   [Python SDK](#tab-panel-1427)
-   [Rust](#tab-panel-1428)
-   [C#](#tab-panel-1429)
-   [Go](#tab-panel-1430)
-   [Node.js](#tab-panel-1431)
-   [C](#tab-panel-1432)
-   [Java](#tab-panel-1433)
-   [Python](#tab-panel-1434)

```java
String exp = "$.visitors.hllUnion($.cohort_a).hllCount() > 0";
```

```python
exp = "$.visitors.hllUnion($.cohort_a).hllCount() > 0"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{gt, hll_bin, int_val};

let exp = gt(

    hll_exp::get_count(

        hll_exp::get_union(hll_bin("cohort_a".into()), hll_bin("visitors".into()))),

    int_val(0));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(

    HLLExp.GetCount(

      HLLExp.GetUnion(Exp.HLLBin("cohort_a"), Exp.HLLBin("visitors"))),

    Exp.Val(0)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

union := as.ExpHLLGetUnion(as.ExpHLLBin("cohort_a"), as.ExpHLLBin("visitors"))

exp := as.ExpGreater(as.ExpHLLGetCount(union), as.ExpIntVal(0))
```

```javascript
const exp = Aerospike.exp

const unionHll = exp.hll.getUnion(

  exp.binHll('visitors'),

  exp.binHll('cohort_a'),

)

const filterExp = exp.gt(exp.hll.getCount(unionHll), exp.int(0))
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_hll_get_count(

      as_exp_hll_get_union(

        as_exp_bin_hll("cohort_a"),

        as_exp_bin_hll("visitors"))),

    as_exp_int(0)));
```

```java
import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.gt(

    HLLExp.getCount(

      HLLExp.getUnion(Exp.hllBin("cohort_a"), Exp.hllBin("visitors"))),

    Exp.val(0)));
```

```python
from aerospike_helpers.expressions import GT, HLLBin

from aerospike_helpers.expressions.hll import HLLGetCount, HLLGetUnion

u = HLLGetUnion(HLLBin("cohort_a"), HLLBin("visitors"))

exp = GT(HLLGetCount(u), 0).compile()
```

---

#### `hll_get_union_count`

```python
hll_get_union_count(hll_list, bin)
```

Description: Returns the estimated number of distinct elements in the union of `hll_list` and the HLL that `bin` evaluates to.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `hll_list` | `list` | 
HLLs to union with the operand.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: Estimated cardinality of the union of `cohort_a` and `visitors` exceeds 500.

-   [Java SDK](#tab-panel-1435)
-   [Python SDK](#tab-panel-1436)
-   [Rust](#tab-panel-1437)
-   [C#](#tab-panel-1438)
-   [Go](#tab-panel-1439)
-   [Node.js](#tab-panel-1440)
-   [C](#tab-panel-1441)
-   [Java](#tab-panel-1442)
-   [Python](#tab-panel-1443)

```java
String exp = "$.visitors.hllUnionCount($.cohort_a) > 500";
```

```python
exp = "$.visitors.hllUnionCount($.cohort_a) > 500"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{gt, hll_bin, int_val};

let exp = gt(

    hll_exp::get_union_count(hll_bin("cohort_a".into()), hll_bin("visitors".into())),

    int_val(500));
```

```csharp
Expression exp = Exp.Build(

  Exp.GT(

    HLLExp.GetUnionCount(Exp.HLLBin("cohort_a"), Exp.HLLBin("visitors")),

    Exp.Val(500)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpGreater(

  as.ExpHLLGetUnionCount(as.ExpHLLBin("cohort_a"), as.ExpHLLBin("visitors")),

  as.ExpIntVal(500),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.gt(

  exp.hll.getUnionCount(

    exp.binHll('visitors'),

    exp.binHll('cohort_a'),

  ),

  exp.int(500),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_gt(

    as_exp_hll_get_union_count(

      as_exp_bin_hll("cohort_a"),

      as_exp_bin_hll("visitors")),

    as_exp_int(500)));
```

```java
import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.gt(

    HLLExp.getUnionCount(Exp.hllBin("cohort_a"), Exp.hllBin("visitors")),

    Exp.val(500)));
```

```python
from aerospike_helpers.expressions import GT, HLLBin

from aerospike_helpers.expressions.hll import HLLGetUnionCount

exp = GT(

    HLLGetUnionCount(HLLBin("cohort_a"), HLLBin("visitors")),

    500,

).compile()
```

---

#### `hll_may_contain`

```python
hll_may_contain(values, bin)
```

Description: Returns 1 if the HLL that `bin` evaluates to may contain every element of `values`, otherwise 0. A positive answer is probabilistic; a negative answer is certain.

Arguments: | Name | Type | Description |
| --- | --- | --- |
| `values` | `list` | 
Elements to look for; the result is 1 only when the HLL may contain every one.

 |
| `bin` | `hll` | 

HLL bin to operate on, or any expression that evaluates to an HLL.

 |

Returns: `integer`

Introduced: 5.2.0.4

Example: The HLL may contain every candidate key listed in list bin `candidate_keys` (returns `1` when the check is positive).

-   [Java SDK](#tab-panel-1444)
-   [Python SDK](#tab-panel-1445)
-   [Rust](#tab-panel-1446)
-   [C#](#tab-panel-1447)
-   [Go](#tab-panel-1448)
-   [Node.js](#tab-panel-1449)
-   [C](#tab-panel-1450)
-   [Java](#tab-panel-1451)
-   [Python](#tab-panel-1452)

```java
String exp = "$.visitors.hllMayContain($.candidate_keys) == 1";
```

```python
exp = "$.visitors.hllMayContain($.candidate_keys) == 1"
```

```rust
use aerospike::expressions::hll as hll_exp;

use aerospike::expressions::{eq, hll_bin, int_val, list_bin};

let exp = eq(

    hll_exp::may_contain(

        list_bin("candidate_keys".into()),

        hll_bin("visitors".into())),

    int_val(1));
```

```csharp
Expression exp = Exp.Build(

  Exp.EQ(

    HLLExp.MayContain(Exp.ListBin("candidate_keys"), Exp.HLLBin("visitors")),

    Exp.Val(1)));
```

```go
// Requires: import as "github.com/aerospike/aerospike-client-go/v8"

exp := as.ExpEq(

  as.ExpHLLMayContain(as.ExpListBin("candidate_keys"), as.ExpHLLBin("visitors")),

  as.ExpIntVal(1),

)
```

```javascript
const exp = Aerospike.exp

const filterExp = exp.eq(

  exp.hll.mayContain(

    exp.binHll('visitors'),

    exp.binList('candidate_keys'),

  ),

  exp.int(1),

)
```

```c
as_exp_build(predexp,

  as_exp_cmp_eq(

    as_exp_hll_may_contain(

      as_exp_bin_list("candidate_keys"),

      as_exp_bin_hll("visitors")),

    as_exp_int(1)));
```

```java
import com.aerospike.client.exp.Exp;

import com.aerospike.client.exp.HLLExp;

Expression exp = Exp.build(

  Exp.eq(

    HLLExp.mayContain(Exp.listBin("candidate_keys"), Exp.hllBin("visitors")),

    Exp.val(1)));
```

```python
from aerospike_helpers.expressions import Eq, HLLBin, ListBin

from aerospike_helpers.expressions.hll import HLLMayContain

exp = Eq(HLLMayContain(ListBin("candidate_keys"), HLLBin("visitors")), 1).compile()
```

---