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 Shell 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 Shell is installed.
Java Development Kit (JDK) V1.8 or later is installed.
The client IP address is added to the Lindorm whitelist.
Step 1: Create a wide table
In Lindorm Shell, call the HBase API to create a wide table named
testTablein the default namespacedefault, and define a column family namedf1.create 'testTable', 'f1'
Step 2: Create a search index
Log on to the LindormSearch GUI. Run the following command to create an index table named democollection:
PUT democollection
{
"settings": {
"index.number_of_shards": 4
},
"mappings": {
"properties": {
"name_s": {"type":"keyword"}
}
}
}If an index query only requires data id and does not need to return the original values of the index columns, you can configure "_source": {"enabled": false} in mappings to reduce resource consumption. Example code:
PUT democollection
{
"settings": {
"index.number_of_shards": 4
},
"mappings": {
"_source": {
"enabled": false
},
"properties": {
"name_s": {
"type": "keyword"
}
}
}
}Step 3: Map wide table columns to index columns
To ensure that data from wide table columns is correctly synchronized to the corresponding search index columns and that the results queried through the search index meets expectations, you need to map wide table columns to search index columns. In this example, the wide table column f1:name is mapped to the index column name_s.
Create a JSON file named
schemain thebindirectory of the decompressed Lindorm Shell folder, and copy the following code to the JSON file:{ "sourceNamespace": "default", "sourceTable": "testTable", "targetIndexName": "democollection", "indexType": "ES", "rowkeyFormatterType": "STRING", "fields": [ { "source": "f1:name", "targetField": "name_s", "type": "STRING" } ] }NoteMake sure that the column names and data types of the wide table and index table in the column mappings are consistent with column names and data types defined when you create the wide table and index table.
For more information about the parameters in the JSON file, see Configure column mapping.
Run the following command in Lindorm Shell to complete the mappings between wide table columns and index table columns:
alter_external_index 'testTable', 'schema.json'NoteFor more information about how to manage the mappings between wide table columns and index table columns, see Manage a column mapping relation.
Step 4: Write data to the wide table
Run the following code to write a data record to the wide table testTable:
put 'testTable', 'row1', 'f1:name', 'foo'After the 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. To synchronize historical data in the wide table, you need to manually create indexes for full data.
Step 5: 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.
GET /democollection/_search { "size": 10, "query": { "match": { "name_s": "foo" } } }The following results are returned:
{ "took": 3, "timed_out": false, "_shards": { "total": 4, "successful": 4, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 0.2876821, "hits": [ { "_index": "democollection", "_id": "row1", "_score": 0.2876821, "_source": { "name_s": "foo", "update_version_l": 1745397126559 } } ] } }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=1745397126559, value=foo 1 row(s)