Secondary Indexes in Aerospike Cloud
Overviewโ
A secondary index (SI) is a data structure that locates all the records in a set, based on a bin value in the record. When a value is updated in the indexed record, the secondary index automatically updates.
After your Aerospike Cloud database has been deployed and you have written data into it, you can plan how to improve query performance with secondary indexes. For more information see secondary index.
Secondary index considerationsโ
In an Aerospike Cloud database, all records must belong to a set. Secondary indexes must be associated with a particular set. Secondary indexes at the namespace level are not allowed in Aerospike Cloud databases.
Aerospike Cloud manages the secondary indexes for each deployment. They cannot be updated or changed directly by client applications.
New secondary indexes may not be immediately available for use by the database. The cloud console displays new indexes as soon as they are created, but there may be a delay before database starts using them.
Each database may use up to 10 secondary indexes.
Create a secondary indexโ
Log in to your Aerospike Cloud console at https://control.aerospike.cloud.
Select an existing database from the dashboard.
Select the Configurations tab near the center of the page.
Scroll down to the Secondary Indexes section of the page. Click Create Secondary Index. A dialog box appears.
The dialog box has the following fields:
Field Description Required? Set Name
Set to be indexed. Yes Index Name
Name of the index. Must be unique for this database. Yes Bin Name
Bin to be indexed. Yes Index Type
Data type of the index. Yes Index Collection Type
If the bin to be indexed contains a Collection Data Type (CDT), specify it here. No CDT Context
To index a nested CDT element, provide a context. See details below. No - Click Create Secondary Index to create the index.
Notes on the CDT Context fieldโ
To index multiple specific nested fields in a CDT, fill in the CDT Context text box with a comma-separated list of values indicating the fields to be indexed. The values have the following format:
<CDT_CONTEXT_TYPE>:<VALUE_TYPE>:<VALUE>:<CDT_ORDER>:<PADDING>
The <CDT_CONTEXT_TYPE>
field is always required. The following CDT context types are available:
Type | Description | Example |
---|---|---|
list_index | List index | list_index::7:: |
list_rank | List rank | list_rank::2:: |
list_value | List value | list_value:integer:2:: list_value:string:two:: |
list_index_create | List index create | list_index_create::2:ordered:true list_index_create::2:unordered:true |
map_index | Map index | map_index::7:: |
map_rank | Map rank | map_rank::2:: |
map_key | Map key | map_key:integer:2:: map_key:string:two:: |
map_value | Map value | map_value:integer:2:: map_value:string:two:: |
map_key_create | Map key create | map_key_create:string:two:key_value_ordered: map_key_create:string:two:unordered: map_key_create:string:two:key_ordered: |
Multiple CDT contextsโ
You can also specify multiple CDT contexts in a comma-separated list to index values that are at multiple nested levels, such as in a JSON document.
Consider a bin named http_requests
which stores data in JSON format. One record
in the http_requests
bin might look like the following:
"http_requests" : {
"request_details" : {
"method" : "POST",
"status" : {
"http_code": 200,
},
"url" : "/register",
},
"request_id" : 227
}
To query records based on the http_code
value, you need a secondary index
on the http_code
field. Use the following CDT context:
map_key:string:request_details::,
map_key:string:status::,
map_key:string:http_code::
See additional examples of CDT Context usage.
Delete a secondary indexโ
All existing secondary indexes are listed on the Configurations tab. To delete a secondary index, click the garbage can icon to the right of each listing.
Additional resourcesโ
The following links contain more information about secondary index usage:
- Go client example
- Java client example
Under the
AerospikeClient
topic, see thecreateIndex()
API. Secondary indexes in the Spark context.