AerospikeC client manual --- query-secondary index management
The Aerospike C client provides the ability to create and delete secondary indexes in the database.
Currently, secondary indexes can be created using a combination of namespace, set, and bin names. The bin value type used to create an index is integer or string ). If an index is defined on a bin containing an integer value and named "x", only records containing bin "x" and whose bin value is an integer are indexed. Other records that contain bin "x" but whose data is not an integer are not indexed.
The index management call is submitted to any node in the Aerospike cluster, and the information is automatically transmitted to the remaining node.
Secondary index creation and deletion are "expensive" operations and should be performed as management tasks rather than as application runtime tasks. Aerospike provides many tools, such as aql, to create, delete, manage, and monitor secondary indexes. The APIS described in this section are provided to build these tools and other tools.
The following describes how to create a secondary index. Each operation specifies the namespace, set, bin, and a name, which uniquely identifies the secondary index in the namespace.
Aerospike_index_integer_create ()-create an index on the bin of the integer value.
Aerospike_index_string_create ()-create an index on the bin of the string value.
The subsequent code snippets reference the sample directory examples/query_examples ].
The following code creates an integer index on the bin named "binX, the created index belongs to the namespace name "test", set Name "test-set", and index ID "idx_binX ".
as_error err;if (aerospike_index_integer_create(&as, &err, NULL, "test", "demoset", "binX", "idx_binX") != AEROSPIKE_OK) { LOG("aerospike_index_integer_create() returned %d - %s", err.code, err.message); return false;}
The operation to delete the secondary index is aerospike_index_remove (), which requires nammespace and the secondary index name.
as_error err;aerospike_index_remove(&as, &err, NULL, "test", "idx_binX");