Secondary index management
The Aerospike C client provides the ability to create and delete secondary indexes in the database.
Currently, the secondary index can be created using a combination of namespace, set, and bin names, and the bin numeric type that can be used to create the index is an integer (integer) or string. If a secondary index is defined on a bin with an integer value, named "X", then only records containing bin "X" and bin value as Integer are indexed. Other records that contain bin "x" but the data is not integer are not indexed.
The index management call is committed to any node in the Aerospike cluster and the information is automatically propagated to the remaining nodes.
The creation and deletion of secondary indexes is an "expensive" operation and should be performed as a management task rather than as an application run-time task. Aerospike provides many tools, such as AQL, to create, delete, manage, and monitor sub-indexes. The APIs described in this section are provided to build these tools and other tools.
Here's how to create a secondary index. Each operation specifies namespace, set, Bin, and a name, uniquely identifying the secondary index in the namespace.
aerospike_index_integer_create()
-Create an index on the integer (integer) value bin.
aerospike_index_string_create()
-Creates an index on a string (string) value bin.
The following code snippet is referenced from the sample directory " Examples/query_examples " .
Please read the section "Creating connections" to understand how to establish a connection to a cluster.
The following code creates an integer index on the bin with the name "Binx", the namespace name of the record being indexed is called "test", the set name is "Test-set", and the index is identified as "idx_ Binx ".
< Span style= "font-family: Microsoft Jas Black" >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 the use of the Nammespace and secondary index names.
as_error err;aerospike_index_remove(&as, &err, NULL, "test", "idx_binX");
original link: http://www.aerospike.com/docs/client/c/usage/query/sindex.html
Translator: Crooked neck belly Q
Aerospike C Client Manual ——— query-secondary index management