通过开源客户端使用搜索索引需要将宽表的数据同步至索引表,同步的方法是建立宽表和索引表的列映射,列映射配置完成后,需要对列映射进行管理操作,包括创建列映射、查看列映射、增加列映射、删除列映射。

前提条件

创建列映射

执行以下命令创建宽表和索引表的列映射:
alter_external_index 'testTable', 'schema.json'
说明 宽表名称为testTableschema.json为宽表和索引表的列映射配置文件。

修改列映射

如果您需要修改宽表和索引表的映射关系,可以修改列映射配置文件schema.json,然后重新创建列映射。
alter_external_index 'testTable', 'new_schema.json'
说明 new_schema.json为修改后的列映射配置文件。

查看列映射

执行以下命令可以查看宽表和索引表的映射关系。
describe_external_index 'testTable'

增加列映射

如果您需要在列映射关系上添加一列或者几列的映射关系,可以执行以下命令。
 add_external_index_field 'testTable', {FAMILY => 'f', QUALIFIER => 'money', TARGETFIELD => 'money_f', TYPE => 'FLOAT' }
说明 执行创建列映射命令(alter_external_index)后,才能执行上述命令增加列映射。如果需要修改的列较多,推荐采用alter_external_index命令一次性提执行。

删除列映射

如果您需要在列映射关系上删除一列或者几列的映射关系,可以执行以下命令。
remove_external_index 'testTable', 'f:name', 'f:age'

删除所有的列映射

  1. 删除列映射配置文件schema.json中所有的列映射配置信息(fields参数中的数据)。
    {
      "sourceNamespace": "default",
      "sourceTable": "testTable",
      "targetIndexName": "democollection",
      "indexType": "SOLR",
      "rowkeyFormatterType": "STRING",
      "fields": []
    }
  2. 执行创建列映射命令。
    alter_external_index 'testTable', 'del_schema.json'
    说明 del_schema.json为删除后的列映射配置文件。

相关文档

如果您需要使用Java API管理列映射,先通过Java API连接Lindorm宽表引擎,具体操作请参见通过HBase Java API连接并使用宽表引擎

与索引管理相关的API在AliHBaseUETable类中,示例如下:
AliHBaseUETable table = (AliHBaseUETable)connection.getTable(TableName.valueOf("testTable"));

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

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