LindormTable provides a new search type named search indexes. This topic describes how to call the Apache HBase API and the Apache Solr API to connect to and use SearchIndex.
Background information
SearchIndex is integrated into LindormTable and LindormSearch to provide unified and easy-to-use API operations to meet various query requirements. LindormTable is compatible with the open source HBase API. LindormSearch is compatible with the Apache Solr API. You can execute Lindorm SQL statements to connect to and use search indexes. This is the standard method. You can also use an open source client to use search indexes. This method is convenient for more uses than the standard method.
Note If you execute a Lindorm SQL statement to create a table, execute SQL statements to use search indexes.
Prerequisites
- Java Development Kit (JDK) 1.8 or later is installed.
- The IP address of your client is added to the whitelist of your Lindorm instance. For more information, see Configure whitelists.
Procedure
- Enter the HBase shell. For more information, see Use HBaseue Shell to connect to and use LindormTable.
- In the HBase shell, create a wide table named
testTable
.create 'testTable', {NAME => 'f'}
- Create an index table named
democollection
. You can use one of the following methods to create an index table:- Use the cluster management system of LindormSearch to create an index table. For more information, see Create a collection.
- Use the search shell to create an index table. For more information, see Use Search Shell to connect to and use LindormSearch.
- Map columns in a wide table to columns in an index table. For example, map the
f:name
column in thetestTable
table to thename_s
column in thedemocollection
index table. In the f:name column, f specifies the column family name and name specifies the name of the column.- In the bin directory of the file that is extracted from the HBase shell package, create a JSON file named schema. Copy the following sample code to the JSON file:
{ "sourceNamespace": "default", "sourceTable": "testTable", "targetIndexName": "democollection", "indexType": "SOLR", "rowkeyFormatterType": "STRING", "fields": [ { "source": "f:name", "targetField": "name_s", "type": "STRING" } ] }
Note For information about the parameters in the JSON file, see Configure column mapping. - Enter the HBase shell and run the following command to configure column mappings between the wide table and the index table:
alter_external_index 'testTable', 'schema.json'
Note For information about how to manage column mappings between a wide table and an index table, see Manage a column mapping relation.
- In the bin directory of the file that is extracted from the HBase shell package, create a JSON file named schema. Copy the following sample code to the JSON file:
- Write a record to the
testTable
table. After column mappings between the wide table and the index table are configured, the data that is written to the wide table is automatically synchronized to the index table in real time. Historical data in a wide table can be synchronized only after you manually create a full index. For more information, see Create indexes for full data.put 'testTable', 'row1', 'f:name', 'foo'
- Query index data.
- Use the cluster management system of LindormSearch to query index data and obtain the primary key
row1
of the wide table. For more information, see Query data. - Enter the HBase shell and run the following command to query data in the wide table:
The following result is returned:get 'testTable','row1'
COLUMN CELL f:name timestamp=1644462597661, value=foo 1 row(s) Took 0.0942 seconds
- Use the cluster management system of LindormSearch to query index data and obtain the primary key
- View the status of real-time data synchronization tasks on the Lindorm Tunnel Service (LTS) web UI. After column mappings between the wide table and the index table are configured, the data that is written to the wide table is automatically synchronized to the index table in real time.