Dropping Indexes
- how-to
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. |
-
N1QL
-
.NET
-
Java
-
Node.js
-
Python
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.
To drop a primary index, use the task DropPrimaryIndexAsync()
on the interface IQueryIndexManager
.
-
Specify the keyspace which contains the index.
-
If the index has a name:
-
Use
DropPrimaryQueryIndexOptions
to specify the index options. -
In the index options, invoke the
IndexName
method.
-
The following example drops an unnamed primary index from the specified keyspace.
await cluster.QueryIndexes.DropPrimaryIndexAsync("`travel-sample`");
The following example drops a named primary index from the specified keyspace.
await cluster.QueryIndexes.DropPrimaryIndexAsync(
"`travel-sample`",
options => options.IndexName("named_primary_index")
);
Click the GitHub button to view this code in context.
For further details, refer to IQueryIndexManager().
To drop a primary index, use the dropPrimaryIndex
method and specify the keyspace which contains the index.
The Java SDK does not provide a call for dropping a named primary index. To drop a named primary index, use a N1QL query. |
The following example drops an unnamed primary index from the specified keyspace.
cluster.queryIndexes().dropPrimaryIndex("travel-sample");
Click the GitHub button to view this code in context.
For further details, refer to QueryIndexManager.
To drop a primary index, use the dropPrimaryIndex
function on a QueryIndexManager
object.
-
Specify the keyspace which contains the index.
-
If the index has a name:
-
Use
DropPrimaryQueryIndexOptions
to specify the index options. -
In the index options, use the
name
property to specify the index name.
-
The following example drops an unnamed primary index from the specified keyspace.
await cluster.queryIndexes().dropPrimaryIndex('travel-sample')
The following example drops a named primary index from the specified keyspace.
await cluster
.queryIndexes()
.dropPrimaryIndex('travel-sample', { name: 'named_primary_index' })
Click the GitHub button to view this code in context.
For further details, refer to QueryIndexManager.
To drop a primary index, use the drop_primary_index
function on a QueryIndexManager
object.
-
Specify the keyspace which contains the index.
-
If the index has a name:
-
Use
DropPrimaryQueryIndexOptions
to specify the index options. -
In the index options, use the
index_name
property to specify the index name.
-
The following example drops an unnamed primary index from the specified keyspace.
cluster.query_indexes().drop_primary_index(
"travel-sample"
)
The following example drops a named primary index from the specified keyspace.
cluster.query_indexes().drop_primary_index(
"travel-sample",
DropPrimaryQueryIndexOptions(index_name="named_primary_index")
)
Click the GitHub button to view this code in context.
For further details, refer to N1QL Index Management.
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. |
-
N1QL
-
.NET
-
Java
-
Node.js
-
Python
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.
To drop a secondary index, use the task DropIndexAsync()
on the interface IQueryIndexManager
.
-
Specify the keyspace which contains the index.
-
Specify the name of the index.
The following example drops a named index from the specified keyspace.
await cluster.QueryIndexes.DropIndexAsync("`travel-sample`", "index_name");
Click the GitHub button to view this code in context.
For further details, refer to IQueryIndexManager().
To drop a secondary index, use the dropIndex
method.
-
Specify the keyspace which contains the index.
-
Specify the name of the index.
The following example drops a named index from the specified keyspace.
cluster.queryIndexes().dropIndex("travel-sample", "index_name");
Click the GitHub button to view this code in context.
For further details, refer to QueryIndexManager.
To drop a secondary index, use the dropIndex
function on a QueryIndexManager
object.
-
Specify the keyspace which contains the index.
-
Specify the name of the index.
The following example drops a named index from the specified keyspace.
await cluster.queryIndexes().dropIndex('travel-sample', 'index_name')
Click the GitHub button to view this code in context.
For further details, refer to QueryIndexManager.
To drop a secondary index, use the drop_index
function on a QueryIndexManager
object.
-
Specify the keyspace which contains the index.
-
Specify the name of the index.
The following example drops a named index from the specified keyspace.
cluster.query_indexes().drop_index("travel-sample", "index_name")
Click the GitHub button to view this code in context.
For further details, refer to N1QL Index Management.