IndexBuilder

class aerospike_sdk.aio.operations.index.IndexBuilder[source]

Bases: object

Configure a secondary index, then create() or drop() it.

Typical chain for a new index: on_bin()named()numeric() or string() → optional collection() or context()await create().

For removal, only named() (and namespace/set from construction) is required before await drop().

Example:

await (
    client.index(namespace="test", set_name="users")
    .on_bin("email")
    .named("email_idx")
    .string()
    .create()
)

See also

index()

__init__(client, namespace, set_name)[source]
Parameters:
  • client (Client) – Connected async cluster client used for admin calls.

  • namespace (str) – Namespace containing the set to index.

  • set_name (str) – Set name within the namespace.

on_bin(bin_name)[source]

Set which bin this secondary index covers (required before create()).

Parameters:

bin_name (str) – Name of the bin to index.

Return type:

IndexBuilder

Returns:

self for method chaining.

named(index_name)[source]

Set the secondary index name the cluster stores (required for create and drop).

Parameters:

index_name (str) – Name passed to create/drop admin calls; must match when dropping.

Return type:

IndexBuilder

Returns:

self for method chaining.

numeric()[source]

Set the secondary index type to numeric (for numeric bin values).

Call this or string() before create(), matching how the bin is stored. If both are called on the same builder, the last call wins.

Return type:

IndexBuilder

Returns:

self for method chaining.

string()[source]

Set the secondary index type to string (for string bin values).

Call this or numeric() before create(). If both are called, the last call wins (see numeric()).

Return type:

IndexBuilder

Returns:

self for method chaining.

collection(collection_index_type)[source]

Set the collection index variant for map or list bins (optional).

Use together with numeric() or string() when indexing into collection data types.

Parameters:

collection_index_type (CollectionIndexType) – CollectionIndexType constant from the aerospike_async package (map- vs list-style collection indexing).

Return type:

IndexBuilder

Returns:

self for method chaining.

context(ctx)[source]

Set a CDT context path for indexing a nested list or map element.

Parameters:

ctx (List[CTX]) – One or more CTX entries describing the path to the nested element (e.g., [CTX.map_key("outer"), CTX.list_index(0)]).

Return type:

IndexBuilder

Returns:

self for method chaining.

Example:

await (
    client.index("test", "events")
    .on_bin("payload")
    .named("nested_ts_idx")
    .numeric()
    .context([CTX.map_key("meta"), CTX.map_key("timestamp")])
    .create()
)

See also

context(): Attach the same path when querying.

async create()[source]

Create the index on the cluster.

Example:

await (
    client.index(namespace="test", set_name="users")
    .on_bin("email")
    .named("email_idx")
    .string()
    .create()
)
Raises:
  • ValueError – If on_bin, named, or index type was not set.

  • AerospikeError – On server or transport failure (typed subclass when the driver maps a result code).

See also

drop()

Return type:

None

async drop()[source]

Drop a previously created index by name.

Example:

await (
    client.index(namespace="test", set_name="users")
    .named("email_idx")
    .drop()
)
Raises:

Note

Namespace and set come from the builder constructor, not from on_bin().

Return type:

None