Secondary Index Creation

The Aerospike Knowledge Base has moved to https://support.aerospike.com. Content on https://discuss.aerospike.com is being migrated to either https://support.aerospike.com or https://docs.aerospike.com. Maintenance on articles stored in this repository ceased on December 31st 2022 and this article may be stale. If you have any questions, please do not hesitate to raise a case via https://support.aerospike.com.

Question:

How do I check if a secondary index already exists? AQL will show me all the indexes but in the Java client I don’t see how to do it. I see that I don’t get any exception if I make a call to recreate an index that already exists. In that case does it a NOOP on the server or are there any side effects like re-indexing?

Answer:

We recommend using SINDEX as a parameter of ASINFO for querying if a secondary index.

$ asinfo -v "sindex"

Please see the examples in the following link for a more detailed usage of SINDEX SINDEX Doc

In the Java client API, you can use either of the ‘request’ methods provided for the query. We recommend the following one for SINDEX for getting one info value by name from the specified database server node. Take a look at the following page.

http://www.aerospike.com/apidocs/java/com/aerospike/client/Info.html#request(com.aerospike.client.cluster.Node, java.lang.String)

When trying recreate the same index the the server returns error and does nothing. Java/C# clients will swallow this error and not throw exception. However, if it is exactly same bintype, set, namespace, it will do some network messaging and then NOOP.