A newer version of this documentation is available.

View Latest
February 16, 2025
+ 12
How to drop primary and secondary indexes.

Introduction

You can drop primary and secondary indexes when you do not need them any more. Dropping an index that has replicas will also drop all of the replica indexes too.

If you want to try out the examples in this section, follow the instructions given in Do a Quick Install to install Couchbase Server, configure a cluster, and load a sample dataset. Read the following for further information about the tools available for editing and executing queries:

Dropping a Primary Index

You can drop a primary index using a N1QL statement or an SDK call.

Prior to the SDK API 3.3 releases (released alongside Server 7.1), the SDK calls only enabled you to drop indexes in the default collection and default scope within a bucket. A N1QL statement enables you to drop indexes in any collection and scope within a bucket.

To drop an unnamed primary index, use the DROP PRIMARY INDEX statement.

To drop a named primary index, use the DROP INDEX statement. There are two possible syntaxes:

  • Specify the index name, then use the ON keyword to specify the keyspace which contains the index.

  • Specify the keyspace and index name using dotted notation.


The following example drops an unnamed primary index from the airline keyspace.

DROP PRIMARY INDEX ON `travel-sample`.inventory.airline;

The following example drops a named primary index from the airline keyspace.

DROP INDEX travel_primary ON `travel-sample`.inventory.airline;

The following example drops the index in exactly the same way, but uses alternative syntax.

DROP INDEX default:`travel-sample`.inventory.airline.travel_primary;

For further details and examples, refer to DROP PRIMARY INDEX and DROP INDEX.

Dropping a Secondary Index

You can drop a secondary index using a N1QL statement or an SDK call.

Prior to the SDK API 3.3 releases (released alongside Server 7.1), the SDK calls only enabled you to drop indexes in the default collection and default scope within a bucket. A N1QL statement enables you to drop indexes in any collection and scope within a bucket.

To drop a a secondary index, use the DROP INDEX statement. There are two possible syntaxes:

  • Specify the index name, then use the ON keyword to specify the keyspace which contains the index.

  • Specify the keyspace and index name using dotted notation.


The following example drops a named index from the airline keyspace.

DROP INDEX `idx-name` ON `travel-sample`.inventory.airline;

The following example drops the index in exactly the same way, but uses alternative syntax.

DROP INDEX default:`travel-sample`.inventory.airline.`idx-name`;

For further details and examples, refer to DROP INDEX.

Reference and explanation:

Administrator guides:

Indexes with SDKs: