Rate This Document
Findability
Accuracy
Completeness
Readability

Deleting an Index

The dropIndices API is used to delete an index.

dropIndices API

  • dropIndices API
    void dropIndices(TableName tableName, List<String> indexNames)
  • Function description

    Clients call this API to delete a specified index table.

  • API description
    1. Package name: package com.huawei.boostkit.hindex
    2. Class name: GlobalIndexAdmin
    3. Method name: dropIndices
    4. Parameter description:

      Parameter

      Value

      Description

      tableName

      TableName

      User data table.

      List<String> indexNames

      List<String>

      Index table to be deleted.

  • Example
    // Create a user table myuser and add data.
    Admin admin = connection.getAdmin();
    TableName myuser = TableName.valueOf("myuser");
    HTableDescriptor hTableDescriptor = new HTableDescriptor(myuser);
    HColumnDescriptor f1 = new HColumnDescriptor("f1");
    hTableDescriptor.addFamily(f1);
    admin.createTable(hTableDescriptor);
    try (Table table = conn.getTable(myuser)) {
        Put put0 = new Put(Bytes.toBytes("001"));
        put0.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), Bytes.toBytes("test"));
        table.put(ImmutableList.of(put0));
    }
    
    // Create an index table myindex.
    TableIndices myindex = new TableIndices();
    HIndexSpecification spec = new HIndexSpecification("myindex");
    // Create an index for q1 in the f1 column family of the data table. The data type is STRING.
    spec.addIndexColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), ValueType.STRING);
    myindex.addIndex(spec);
    GlobalIndexAdmin globalIndexAdmin = GlobalIndexClient.newIndexAdmin(admin);
    globalIndexAdmin.addIndicesWithData(myuser, myindex);
    
    // Delete the myindex index table.
    globalIndexAdmin.dropIndices(myuser, Collections.singletonList("myindex"));
  • Result

    The myindex index table is successfully deleted.