Updated on 2026-06-29 GMT+08:00

Disabling HBase Global Secondary Indexes

Function

The index status of the global secondary index determines whether the index is valid. By modifying the index status, you can disable, enable, or discard the index (no index data is generated). You can modify the index status by calling the method in org.apache.hadoop.hbase.hindex.global.GlobalIndexAdmin.

Code Sample

The following code snippets are in the GlobalSecondaryIndexSample class of the com.huawei.bigdata.hbase.examples package.

In this case, the idx_id_age index is disabled. That is, the index is not used during query, but index data is generated.

/**
    * alter index to UNUSABLE state.
    */
public void testAlterIndex() {
    LOG.info("Entering testAlterIndex.");
    List<String> indexNameList = Lists.newArrayList("idx_id_age");
    // Instantiate HIndexAdmin Object
    try (GlobalIndexAdmin iAdmin = GlobalIndexClient.newIndexAdmin(conn.getAdmin())) {
        iAdmin.alterGlobalIndicesUnusable(tableName, indexNameList);
        LOG.info("Alter indices to UNUSABLE successfully.");
    } catch (IOException e) {
        LOG.error("Alter indices to UNUSABLE failed.", e);
    }
    LOG.info("Exiting testAlterIndex.");
}