Lindorm supports search indexes for wide tables. After you create a search index and configure mapping, data written to a wide table is automatically synchronized to LindormSearch. You can call the Elasticsearch API to perform queries. This topic describes how to use Lindorm-cli to manage search indexes and perform real-time queries on structured data.
Prerequisites
LindormTable is activated for the Lindorm instance.
The search index feature is enabled for your Lindorm instance.
NoteThis search index feature depends on LindormSearch and Lindorm Tunnel Service (LTS). To enable this feature, you must also activate LindormSearch and LTS.
Lindorm-cli is installed.
Lindorm Shell is installed.
Java Development Kit (JDK) V1.8 or later is installed.
The client IP address is added to the Lindorm whitelist.
A wide table is created by using the HBase API. In this topic, the wide table name is
testTable, and the column family name isf1.
Step 1: Map data types of wide table columns
Use Lindorm-cli to map data types of wide table columns to ensure that data written to the wide table can be parsed in the correct format and synchronized to the search index. In this example, the
Rowkeyandf1:namecolumns of the wide table are mapped asHSTRINGtype.ALTER TABLE testTable MAP DYNAMIC COLUMN`ROW` HSTRING, f1:name HSTRING;For more information, see data type mappings.
NoteTo make the Rowkey (the
ROWfield in the preceding code) stored in the wide table consistent with the primary key ID stored in LindormSearch, you need to map the Rowkey data type asHSTRINGbefore creating the index.Otherwise, the Rowkey of the wide table is mapped to the primary key of the search index table in HEX encoding format. For more information, see parameter description of rowkeyFormatterType.
Step 2: Create a search index
Create a search index named idx in Lindorm-cli.
CREATE INDEX idx USING SEARCH ON testTable (f1:name);By default, raw data is not stored in the search index. To directly access the raw data of the index columns in the search index table, you can specify the SOURCE_SETTINGS attribute when you create the index.
CREATE INDEX idx USING SEARCH ON testTable(f1:name) WITH (SOURCE_SETTINGS='
{
"enabled": true
}
');After the created search index becomes
ACTIVE, data written to the wide table is automatically synchronized to the index table in real time. For information about how to view the index status, see SHOW INDEX. To synchronize historical data in the wide table, you need to execute theALTER INDEXstatement to rebuild indexes. Example:ALTER INDEX idx ON testTable REBUILD;, whereidxindicates the index name of the wide table search index.To disconnect from Lindorm-cli, run the
exit,quit, orctrl+dcommand. For more Lindorm-cli commands, see Common commands used in Lindorm-cli.
Step 3: Write data to the wide table
In Lindorm Shell, call the HBase API to insert a data record into the table
testTable.put 'testTable', 'row1', 'f1:name', 'foo'
Step 4: Use search indexes to query data
Query index data.
Log on to the LindormSearch GUI. Call the Elasticsearch API to query index data and obtain the primary key ID of the search index table.
NoteThe name of the LindormSearch index table is concatenated in the format of
<Namespace name>.<Table name>.<Index name>.The column names in a search index table are concatenated based on the following rules:
When the column family of the wide table is
f, the column name in the wide table and index table is the same. For example,f:namecorresponds toname.When the column family of the wide table is not
f, the column name in the index table is in the format of<Column family name>_<Column name>. For example,f1:namecorresponds tof1_name.
GET /default.testTable.idx/_search { "size": 10, "query": { "match": { "f1_name": "foo" } } }The following results are returned:
{ "took": 8, "timed_out": false, "_shards": { "total": 4, "successful": 4, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 0.2876821, "hits": [ { "_index": "default.testTable.idx", "_id": "row1", "_score": 0.2876821, "_source": { "_searchindex_id": "row1", "update_version_l": 1745389294641, "f1_name": "foo" } } ] } }Obtain the primary key ID (
_id) of the search index table from the results.Run the following command in Lindorm Shell to query wide table data:
get 'testTable','row1'The following results are returned:
COLUMN CELL f1:name timestamp=1745389294641, value=foo 1 row(s)