How to create an unique index?

Hello

I am using python client,and i want to know how to create an unique index using aql or python client

ThankYou

What do you mean by unique index? You can build a secondary index on numeric of string values in a particular bin of a record. In AQL, type HELP and look at CREATE INDEX syntax.

I think you mean unique index in the RDBMS sense. You should understand the two types of indexes Aerospike does have:

  • Primary Index - similar to a primary key index in a single RDBMS table. If you denormalized your schema to where it’s mostly single table primary key access (or a many to one join to dependent tables), that you’re performing key-value access. This also applies to most REST type access of GET, PUT, DELETE, POST of a resource with a unique identifier. Every object stored in an Aerospike database has a 64B metadata entry in the primary index.
  • Secondary Index - these are optional indexes that support queries against multiple records matching a specific predicate. This is like an INDEX in an RDBMS, which is not unique. You can also query for values without a secondary index using predicate filtering against a scan, similar to a SELECT with a WHERE clause against a column that does not have an index built on it. With a secondary index, as with an index in an RDBMS, you’ll get faster query execution time, but pay for that speed with (DRAM) space allocated for the index. See examples for the PredExp class of the Java client.

Piyush pointed you in the direction of creating secondary indexes through AQL, which is the recommended way. You can also do this through all the language clients. The Python client has methods such as aerospike.Client.index_string_create and others.

1 Like

Thank you @pgupta @rbotzer