All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Enumerations | Functions
Index Operations

Description

The Index API provides the ability to create and remove secondary indexes.

Aerospike currently supports indexing of strings and integers.

String Indexes

A string index allows for equality lookups. An equality lookup means that if you query for an indexed bin with value "abc", then only the records containing bins with "abc" will be returned.

Integer Indexes

An integer index allows for either equality or range lookups. An equality lookup means that if you query for an indexed bin with value 123, then only the records containing bins with the value 123 will be returned. A range lookup means that you can query bins within a range. So, if your range is (1...100), then all records containing the a value in that range will be returned.

+ Collaboration diagram for Index Operations:

Data Structures

struct  as_index_task
 

Enumerations

enum  as_index_type { AS_INDEX_TYPE_DEFAULT, AS_INDEX_TYPE_LIST, AS_INDEX_TYPE_MAPKEYS, AS_INDEX_TYPE_MAPVALUES }
 

Functions

static as_status aerospike_index_create (aerospike *as, as_error *err, as_index_task *task, const as_policy_info *policy, const char *ns, const char *set, const char *bin_name, const char *index_name, as_index_datatype dtype)
 
static as_status aerospike_index_create_complex (aerospike *as, as_error *err, as_index_task *task, const as_policy_info *policy, const char *ns, const char *set, const char *bin_name, const char *index_name, as_index_type itype, as_index_datatype dtype)
 
AS_EXTERN as_status aerospike_index_create_ctx (aerospike *as, as_error *err, as_index_task *task, const as_policy_info *policy, const char *ns, const char *set, const char *bin_name, const char *index_name, as_index_type itype, as_index_datatype dtype, struct as_cdt_ctx *ctx)
 
AS_EXTERN as_status aerospike_index_create_wait (as_error *err, as_index_task *task, uint32_t interval_ms)
 
static as_status aerospike_index_integer_create (aerospike *as, as_error *err, const as_policy_info *policy, const char *ns, const char *set, const char *bin, const char *name)
 
AS_EXTERN as_status aerospike_index_remove (aerospike *as, as_error *err, const as_policy_info *policy, const char *ns, const char *index_name)
 
static as_status aerospike_index_string_create (aerospike *as, as_error *err, const as_policy_info *policy, const char *ns, const char *set, const char *bin, const char *name)
 

Enumeration Type Documentation

Index Type

Enumerator
AS_INDEX_TYPE_DEFAULT 
AS_INDEX_TYPE_LIST 
AS_INDEX_TYPE_MAPKEYS 
AS_INDEX_TYPE_MAPVALUES 

Definition at line 63 of file aerospike_index.h.

Function Documentation

static as_status aerospike_index_create ( aerospike as,
as_error err,
as_index_task task,
const as_policy_info policy,
const char *  ns,
const char *  set,
const char *  bin_name,
const char *  index_name,
as_index_datatype  dtype 
)
inlinestatic

Create secondary index given data type.

This asynchronous server call will return before the command is complete. The user can optionally wait for command completion by using a task instance.

if (aerospike_index_create(&as, &err, &task, NULL, "test", "demo", "bin1",
"idx_test_demo_bin1", AS_INDEX_NUMERIC) == AEROSPIKE_OK) {
aerospike_index_create_wait(&err, &task, 0);
}
Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
taskThe optional task data used to poll for completion.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
nsThe namespace to be indexed.
setThe set to be indexed.
bin_nameThe bin name to be indexed.
index_nameThe name of the index.
dtypeThe data type of index, string or integer.
Returns
AEROSPIKE_OK if successful. Return AEROSPIKE_ERR_INDEX_FOUND if index exists. Otherwise an error.

Definition at line 237 of file aerospike_index.h.

References aerospike_index_create_ctx(), and AS_INDEX_TYPE_DEFAULT.

static as_status aerospike_index_create_complex ( aerospike as,
as_error err,
as_index_task task,
const as_policy_info policy,
const char *  ns,
const char *  set,
const char *  bin_name,
const char *  index_name,
as_index_type  itype,
as_index_datatype  dtype 
)
inlinestatic

Create secondary index given collection type and data type.

This asynchronous server call will return before the command is complete. The user can optionally wait for command completion by using a task instance.

if (aerospike_index_create_complex(&as, &err, &task, NULL, "test", "demo", "bin1",
"idx_test_demo_bin1", AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC) == AEROSPIKE_OK) {
aerospike_index_create_wait(&err, &task, 0);
}
Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
taskThe optional task data used to poll for completion.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
nsThe namespace to be indexed.
setThe set to be indexed.
bin_nameThe bin name to be indexed.
index_nameThe name of the index.
itypeThe type of index, default or complex type.
dtypeThe data type of index, string or integer.
Returns
AEROSPIKE_OK if successful. Return AEROSPIKE_ERR_INDEX_FOUND if index exists. Otherwise an error.

Definition at line 197 of file aerospike_index.h.

References aerospike_index_create_ctx().

AS_EXTERN as_status aerospike_index_create_ctx ( aerospike as,
as_error err,
as_index_task task,
const as_policy_info policy,
const char *  ns,
const char *  set,
const char *  bin_name,
const char *  index_name,
as_index_type  itype,
as_index_datatype  dtype,
struct as_cdt_ctx ctx 
)

Create secondary index given collection type, data type and context.

This asynchronous server call will return before the command is complete. The user can optionally wait for command completion by using a task instance.

as_cdt_ctx_init(&ctx, 1);
if (aerospike_index_create_ctx(&as, &err, &task, NULL, "test", "demo", "bin1",
"idx_test_demo_bin1", AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC, &ctx) == AEROSPIKE_OK) {
aerospike_index_create_wait(&err, &task, 0);
}
Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
taskThe optional task data used to poll for completion.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
nsThe namespace to be indexed.
setThe set to be indexed.
bin_nameThe bin name to be indexed.
index_nameThe name of the index.
itypeThe type of index, default or complex type.
dtypeThe data type of index, string or integer.
ctxOptional CDT context describing the path to locate the data to be indexed.
Returns
AEROSPIKE_OK if successful. Return AEROSPIKE_ERR_INDEX_FOUND if index exists. Otherwise an error.
AS_EXTERN as_status aerospike_index_create_wait ( as_error err,
as_index_task task,
uint32_t  interval_ms 
)

Wait for asynchronous task to complete using given polling interval.

Parameters
errThe as_error to be populated if an error occurs.
taskThe task data used to poll for completion.
interval_msThe polling interval in milliseconds. If zero, 1000 ms is used.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
static as_status aerospike_index_integer_create ( aerospike as,
as_error err,
const as_policy_info policy,
const char *  ns,
const char *  set,
const char *  bin,
const char *  name 
)
inlinestatic

Create a new secondary index on an integer bin.

Deprecated:
Use aerospike_index_create() instead.

Definition at line 298 of file aerospike_index.h.

References aerospike_index_create_complex(), AS_INDEX_NUMERIC, and AS_INDEX_TYPE_DEFAULT.

AS_EXTERN as_status aerospike_index_remove ( aerospike as,
as_error err,
const as_policy_info policy,
const char *  ns,
const char *  index_name 
)

Removes (drops) a secondary index.

if (aerospike_index_remove(&as, &err, NULL, "test", idx_test_demo_bin1") != AEROSPIKE_OK) {
fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
nsThe namespace containing the index to be removed.
index_nameThe name of the index to be removed.
Returns
AEROSPIKE_OK if successful or index does not exist. Otherwise an error.
static as_status aerospike_index_string_create ( aerospike as,
as_error err,
const as_policy_info policy,
const char *  ns,
const char *  set,
const char *  bin,
const char *  name 
)
inlinestatic

Create a new secondary index on a string bin.

Deprecated:
Use aerospike_index_create() instead.

Definition at line 314 of file aerospike_index.h.

References aerospike_index_create_complex(), AS_INDEX_STRING, and AS_INDEX_TYPE_DEFAULT.