Search indexes use inverted indexes and column stores to address complex query needs when a large amount of data exists. After you create a search index in the Tablestore console, you can use the search index to query data.

Prerequisites

A data table for which the max versions parameter is set to 1 is created. For more information, see the Create a data table section in Manage the Wide Column model in the Tablestore console.

Step 1: Create a search index

  1. Log on to the Tablestore console.
  2. On the Overview page, click the name of the desired instance or click Manage Instance in the Actions column of the desired instance.
  3. In the Tables section of the Instance Details tab, click the name of a data table and then click the Indexes tab. You can also click Indexes in the Actions column of the data table.
  4. On the Indexes tab, click Create Search Index.
  5. In the Create Index dialog box, create a search index.
    fig_tablestore_009
    1. By default, the system generates a search index name. You can also set Index Name to a specific value.
    2. The default value of Time to Live is -1. You can specify another value based on your business requirements.
      A valid value can be equal to or greater than 86400 seconds, which means one day, or -1, which means the data never expires. The TTL value of a search index must be smaller than or equal to the TTL value of the data table for which the search index is created. For more information, see TTL of search indexes.
      Notice To use the TTL feature, you must set Allow Updates to No for the data table for which the search index is created.
    3. Set Schema Generation Type.
      Notice The Field Name and Field Type values must match those in the data table. For more information about the mappings between the fields in data tables and those in search indexes, see Data type mappings.
      • If you set Schema Generation Type to Manual, set field names and field types for the field values. Specify whether to turn on Array.
      • If you set Schema Generation Type to Auto Generate, the system automatically uses the primary key columns and attribute columns of the data table as indexed fields. Set field types for the field values and specify whether to turn on Array based on your business requirements.
      Note To optimize performance in some cases, you can use virtual columns. For more information, see Virtual columns.
  6. Click OK.

    After the search index is created, click Index Details in the Actions column of the search index. You can view the information about the search index, such as the metering information and index fields.

Step 2: Query data

  1. Log on to the Tablestore console.
  2. On the Overview page, click the name of the desired instance or click Manage Instance in the Actions column of the desired instance.
  3. In the Tables section of the Instance Details tab, click the name of a data table and then click the Indexes tab. You can also click Indexes in the Actions column of the data table.
  4. On the Indexes tab, find the search index that you want to use to query data and click Manage Data in the Actions column.
    fig_tablestore_010
  5. In the Search dialog box, configure query conditions.
    1. By default, the system returns all attribute columns. To return specified attribute columns, turn off All Columns and enter the attribute columns to return. Separate multiple attribute columns with commas (,).
      Note By default, the system returns all primary key columns of data tables.
    2. Select indexed fields. Click Add. Set query methods and values for the fields.
    3. By default, the sorting feature is disabled. To enable sorting, turn on Sort to sort query results based on the indexed fields. Add the indexed fields based on which the query results are sorted and configure sorting methods.
  6. Click OK.
    Data that meets the query conditions is displayed in the specified order on the Indexes tab.

Related operations

  • If you want to add, update, or delete indexed columns from a search index, you can use the feature that allows you to dynamically modify the schema of search indexes. For more information, see Dynamically modify schemas.
  • If you want to query new fields or data of new field types without modifying the storage schema and the data in data tables, you can use the virtual column feature. For more information, see Virtual columns.