Skip to main content

Index Management

Creating an Index

deprecated

Managing sindexes is deprecated as of aql 7.0. Use asadm instead.

The following is the command to create a new secondary index:

CREATE [indextype] INDEX <index> ON <ns>[.<set>] (<bin>) <type>

This will create an index named <index> on bin <bin> of type <type> in the namespace <ns> and set <set>.

Where

  • <indextype> is the type of index (LIST, MAPKEYS, MAPVALUES). The value is optional if not specified defaults to basic index on the bin
  • <index> is the name of the index to be created. The index name must be unique within a namespace. The index name should not exceed 20 characters in length. The index name should not include colon (:) or semicolon (;).
  • <ns> is the namespace to which the index will belong, but is also the namespace containing the record to be indexed.
  • <set> is the set, which will contain the records to be indexed. The <set> is optional, and if not specified, will index records not belonging to a set.
  • <bin> is the name of the bin to be indexed.
  • <type> is the type of the value stored in the <bin> must be either: NUMERIC or STRING or GEO2DSPHERE.

Additional indexing rules:

  • Any record containing bin <bin>, but does not match the specified <type> will not be indexed.
  • Any record that does not contain bin <bin> will not be indexed.

The secondary index will be built in the background, and will not be query-able until it is completely built. If you attempt to query on an index that is not yet complete, you will receive an "Index not active" error.

The following is an example of creating a "numeric" index named "numindex" on bin "binB" of records in "test" namespace and "testset" set.

aql> CREATE INDEX numindex ON test.testset (binB) NUMERIC

The following is an example of creating a "string" list type index named "strindex" on bin "binB" of records in "test" namespace and "testset" set.

aql> CREATE LIST INDEX strindex ON test.testset (binB) STRING

The following is an example of creating a "geospatial" index named "geoindex" on bin "geobin" or records in "test" namespace and "testset" set.

aql> CREATE INDEX geoindex ON test.testset (geobin) GEO2DSPHERE

Listing Indexes

The following is the command to list all the indexes within a cluster:

SHOW INDEXES [<ns>]

The <ns> parameter, will only list indexes in the specified namespace.

The following is an example of listing indexes in "test" namespace:

aql> show indexes test
+--------+--------+-----------+-----------+-------+------------+--------+------------+-----------+
| ns | bin | indextype | set | state | indexname | path | sync_state | type |
+--------+--------+-----------+-----------+-------+------------+--------+------------+-----------+
| "test" | "binB" | "NONE" | "testset" | "RW" | "numindex" | "binB" | "synced" | "NUMERIC" |
| "test" | "binC" | "LIST" | "testset" | "RW" | "strindex" | "binC" | "synced" | "STRING" |
+--------+--------+-----------+----------+-------+------------+---------+------------+-----------+
2 rows in set (0.001 secs)

Dropping an Index

deprecated

Managing sindexes is deprecated as of aql 7.0. Use asadm instead.

The following is the command to drop (remove) a secondary index from a namespace:

DROP INDEX <ns> <index>

This will atomically drop (remove) the index named <index> in the <ns> namespace across the entire cluster.

Where

  • <ns> is the namespace containing the index to be dropped.
  • <index> is the name of the index to be dropped.

The following is an example of dropping the "numindex" index from "test" namespace:

aql> drop index test numindex