Quick start for search index

更新时间:
复制 MD 格式

To run complex queries, such as searching by non-primary key columns or combining multiple conditions, create a search index for your data table. This topic shows you how to quickly get started with a search index in the console.

Note

You can also use an SDK or the CLI to quickly get started with a search index.

Prerequisites

A data table has been created. The max Versions for the data table must be 1, and its time to live (TTL) must meet one of the following conditions:

  • The time to live (TTL) of the data table is -1, which means the data never expires.

  • If the time to live (TTL) is not -1, updates to the data table must be disabled. This means Allow Updates is set to No.

Procedure

Step 1: Create a search index

Create a search index to accelerate data queries. You must add the fields that you want to query and can optionally configure advanced settings such as Routing Key, time to live (TTL), and Pre-sorting.

  1. Go to the Indexes tab.

    1. Log on to the Tablestore console.

    2. In the top navigation bar, select a resource group and a region.

    3. On the Overview page, click the instance name or click Manage Instance in the Actions column.

    4. On the Instance Details tab, in the Tables area, click the data table name or click Indexes in the Actions column.

  2. On the Indexes tab, click Create Search Index.

  3. In the Create Index dialog box, set the index name as needed.

  4. For Auto Generate, select Auto Generate, then select the field types and enable array support if needed.

    The search index is named exampletable_index and includes four columns: id (Fuzzy Keyword), cost (Double), name (Text), and age (Long).

    Important

    The Field Name and data type for each indexed field must match the corresponding field in the data table.

    In the Create Index dialog box, select Search Index as the index type and set Index Name to exampletable_index. For Schema Generation Type, select Auto Generate. The system automatically generates the field configuration: id (Fuzzy Keyword), cost (Double), name (Text), and age (Long). Confirm the configuration and click OK.

  5. Click OK.

    After the search index is created, in the index list, click Index Details in the Actions column to view its basic information, index metrics, Routing Key, indexed fields, and Pre-sorting information.

Step 2: Querying and analyzing data

When you query data using a search index, select a query type that suits your use case. You can also specify which columns to return, how to sort the results, and whether to collect statistics.

This example shows how to use a range query to find rows with a cost value between 10 and 1,000 (inclusive), and then calculate the sum of the cost values for the results.

  1. On the Indexes tab, find the target search index and click Manage Data in the Actions column.

  2. In the Search dialog box, select cost as the index field and click Add.

  3. Configure the range query conditions.

    1. Set Query Type to Range Query (RangeQuery).

    2. Set the maximum value to 1000 and the minimum value to 10.

  4. Enable the Collect Statistics option and configure the settings.

    1. Select cost as the statistics field and click Add.

    2. Set Statistics Type to Sum and set Item to costtotal.

  5. Click OK.

    The query results are displayed on the Indexes tab.

FAQ

Related documents

The console supports several query types for a search index, including term query, terms query, range query, prefix query, suffix query (for Fuzzy Keyword fields only), wildcard query, match query, match phrase query, exists query, boolean query, geo queries (such as geo distance query, geo bounding box query, and geo polygon query, which can be used only on geo-point fields), nested query (for nested fields only), and KNN vector query.