If you want to use SearchIndex by using an open source client, synchronize data in a wide table to an index table. To synchronize data in the wide table to the index table, create column mappings between the wide table and the index table. After you specify configuration items in a file that is used for mapping columns between the wide table and the index table, you can manage the column mapping relation between the tables. For example, you can create, query, add, or delete column mappings. This topic describes how to manage a column mapping relation.

Prerequisites

  • Java Development Kit (JDK) 1.8 or later is installed.
  • Your open source client is connected to SearchIndex, and configuration items in your file used for mapping columns between a wide table and an index table are specified. For more information, see Use an open source client to connect to and use SearchIndex.

Create column mappings

Run the following command to create column mappings between a wide table and an index table:
alter_external_index 'testTable', 'schema.json'
Note In this command, testTable is the name of the wide table and schema.json is the name of the configuration file used for mapping columns between the wide table and the index table.

Modify a column mapping relation

If you want to modify the column mapping relation between your wide table and index table, you can modify the schema.json configuration file and recreate a mapping relation between the tables.
alter_external_index 'testTable', 'new_schema.json'
Note new_schema.json is the name of the modified configuration file that is used for mapping columns.

Query column mappings

Run the following command to view the column mappings between a wide table and an index table:
describe_external_index 'testTable'

Add column mappings

If you want to add one or more column mappings to the existing mapping relation, run the following command:
 add_external_index_field 'testTable', {FAMILY => 'f', QUALIFIER => 'money', TARGETFIELD => 'money_f', TYPE => 'FLOAT' }
Note You can run the preceding command to add column mappings only after the alter_external_index command is run. We recommend that you run the alter_external_index command if you want to add a large number of column mappings.

Delete column mappings

If you want to delete one or more column mappings, run the following command:
remove_external_index 'testTable', 'f:name', 'f:age'

Delete all column mappings

  1. Delete data that you enter for fields in the schema.json file.
    {
      "sourceNamespace": "default",
      "sourceTable": "testTable",
      "targetIndexName": "democollection",
      "indexType": "SOLR",
      "rowkeyFormatterType": "STRING",
      "fields": []
    }
  2. Run the following command to modify the column mapping relation:
    alter_external_index 'testTable', 'del_schema.json'
    Note The del_schema.json file is the column-mapping configuration file that is created after you delete the data.

References

If you want to use Java API operations to manage column mappings, call a Java API operation to connect to LindormTable. For more information, see Use the ApsaraDB for HBase API for Java to connect to and use the wide table engine LindormTable.

The API operations that correspond to index management are in the AliHBaseUETable class. The following sample code provides examples:
AliHBaseUETable table = (AliHBaseUETable)connection.getTable(TableName.valueOf("testTable"));

void addExternalIndex(ExternalIndexConfig config, List<ExternalIndexField> fields) throws IOException;

void removeExternalIndex(List<String> fields) throws IOException;