IndexBuilder¶
- class aerospike_sdk.aio.operations.index.IndexBuilder[source]¶
Bases:
objectConfigure a secondary index, then
create()ordrop()it.Typical chain for a new index:
on_bin()→named()→numeric()orstring()→ optionalcollection()orcontext()→awaitcreate().For removal, only
named()(and namespace/set from construction) is required beforeawaitdrop().Example:
await ( client.index(namespace="test", set_name="users") .on_bin("email") .named("email_idx") .string() .create() )
See also
- 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:
- Returns:
selffor 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:
- Returns:
selffor method chaining.
- numeric()[source]¶
Set the secondary index type to numeric (for numeric bin values).
Call this or
string()beforecreate(), matching how the bin is stored. If both are called on the same builder, the last call wins.- Return type:
- Returns:
selffor method chaining.
- string()[source]¶
Set the secondary index type to string (for string bin values).
Call this or
numeric()beforecreate(). If both are called, the last call wins (seenumeric()).- Return type:
- Returns:
selffor method chaining.
- collection(collection_index_type)[source]¶
Set the collection index variant for map or list bins (optional).
Use together with
numeric()orstring()when indexing into collection data types.- Parameters:
collection_index_type (
CollectionIndexType) –CollectionIndexTypeconstant from theaerospike_asyncpackage (map- vs list-style collection indexing).- Return type:
- Returns:
selffor method chaining.
- context(ctx)[source]¶
Set a CDT context path for indexing a nested list or map element.
- Parameters:
ctx (
List[CTX]) – One or moreCTXentries describing the path to the nested element (e.g.,[CTX.map_key("outer"), CTX.list_index(0)]).- Return type:
- Returns:
selffor 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
- Return type:
- async drop()[source]¶
Drop a previously created index by name.
Example:
await ( client.index(namespace="test", set_name="users") .named("email_idx") .drop() )
- Raises:
ValueError – If
named()was not called.AerospikeError – On server or transport failure.
Note
Namespace and set come from the builder constructor, not from
on_bin().- Return type: