You are viewing the documentation for a prerelease version.

View Latest


The ALTER INDEX statement moves the placement of an existing index or replica among different GSI nodes.

(Introduced in Couchbase Server 5.5 Enterprise Edition)


Use the ALTER INDEX statement to change the placement of an existing index or replica among different GSI nodes when you encounter any of the following situations:

  • An imbalance occurs due to a particular index growing faster than expected and is needed on a different node.

  • An imbalance occurs due to a cluster of indexes being dropped on a single node.

  • A machine is scheduled for removal, so its indexes need to move off its current node.

  • The automated process of rebalancing does not give the expected results.

  • Other types of scaling up or scaling down are needed.

For example, if a node fails and you need to move it from node to node, then you can simply execute the following code with your own index names and addresses:

CREATE INDEX idx1 ON `travel-sample`(id, airline) WHERE type="route";

ALTER INDEX `travel-sample`.idx1
WITH {"action":"move","nodes": [""]}
The ALTER INDEX move operation is asynchronous. As soon as the move alter index command is executed, the command returns. If there is no error in the input, the move operation can be tracked through the console UI and any error can be found in the Console logs and Indexer logs.

If a node goes down while an ALTER INDEX operation is in progress, then the index would rollback to its original node (not affecting queries) and a notification would appear.


Only users with the suitable RBAC role of Administrator are allowed to run the ALTER INDEX directive.

This directive is applicable only for Standard GSI (Plasma) and MOI Indexes; and hence supported only for Enterprise Edition nodes. (Not Applicable for Forest DB).

This statement is supported only from 5.5 onwards; if the cluster is in mix-mode (a mix of 5.5 and previous versions), then this directive will not work.

ALTER INDEX will not work while the cluster is undergoing a Rebalance.


alter index clause
alter index action clause
alter index node clause
ALTER INDEX key_expr
WITH {"action":"action_name", "nodes": [ "node_expr" [, "node_expr2"]* }



[Required] String representing the corresponding named keyspace reference, with an optional index name for example named_keyspace_ref.index_name.



Uses the Global Secondary Index.


[Required] Specifies the alter operation that needs to be performed.


[Required] Reserved word for denoting the single action_name operation to be performed.


[Required] Moves only 1 index (or its replica) at a time to a different node while not making any changes to the index topology, for example, the number of replicas remain the same.

The length of the nodes array must be equal to the number of index replicas.

[Required] Reserved word for denoting the node list that specifies the new destination nodes for the index and its replicas.

The full node list needs to be specified even if only 1 replica needs to be moved.

[Required] String of the destination node address or addresses.

Return Value

If the ALTER INDEX succeeds, then:

  • The Query Workbench will show { Results: [] }

  • The index progress will be visible on the UI.

  • After the movement is complete, the new indexes will begin to service query scans.

  • The command line will display the new index nodes.

If the ALTER INDEX fails, then:

  • The original indexes will continue to service query scans.

  • The UI Log and Query Workbench will have the appropriate error message.

  • Some common errors include:

    Error Message Possible Cause

    GSI index xxxxxxxx not found

    • Mistyped an index name

    Missing Node Information For Move Index

    • Mistyped "node" instead of "nodes"

    • Mistyped punctuation or other item

    No Index Movement Required for Specified Destination List

    • Entered the current node instead of the target node

    syntax error - at \",\"

    • Missed a double-quote mark (")

    Unable to find Index service for destination or destination is not part of the cluster

    • Address doesn’t exist or was mistyped

    • Node isn’t running

    • Node not properly added to the cluster

    Unsupported action value

    • Mistyped the "action"


When using the below examples, make sure Couchbase Server 5.5 Enterprise Edition is already running on the named nodes.

Example 1: Move the def_faa index from one node to another.

Create a cluster of 3 nodes and then go to Settings > Sample buckets to install the travel-sample bucket. The indexes will then be installed in a round-robin fashion and distributed over the 3 nodes. Then move the def_faa index from the first node ( in the screenshot) to the second node ( in the screenshot).

alter index servers step1
ALTER INDEX `travel-sample`.def_faa
WITH {"action":"move","nodes": [""]}

You should see:

  "results": []
alter index servers step2

Example 2: Create and move an index replica from one node to another.

Create an index on node with a replica on node, then move its replica from node to

CREATE INDEX country_idx ON `travel-sample`(country, city)
       WHERE type="route" USING GSI
       WITH {"nodes":["", ""]};

ALTER INDEX `travel-sample`.country_idx
WITH {"action":"move","nodes": ["", ""]}

Example 3: Moving multiple replicas.

Create an index on node with replicas on nodes and, then move the replicas to nodes and

CREATE INDEX country_idx ON `travel-sample`(country, city)
WITH {"nodes": ["", "", ""]}

ALTER INDEX `travel-sample`.country_idx
WITH {"action":"move","nodes":
      ["", "", ""]}

Example 4: Removing an extra replica.

To avoid any downtime, before removing a replica (or index), first create an equivalent index for your queries to continue using.

If you created an index on node with replicas on nodes and and later decided you didn’t want the 2nd replica, then you’ll need to remove the index (which removes all replicas) and then re-create the index with only one replica.

CREATE INDEX country_idx ON `travel-sample`(country, city)
WHERE type="route" USING GSI
WITH {"nodes":["", "", ""]};

DROP INDEX `travel-sample`.country_idx;

CREATE INDEX country_idx ON `travel-sample`(country, city)
WHERE type="route" USING GSI
WITH {"nodes":["", ""]};