You can dynamically modify the schema of a search index. For example, you can add, update, or delete index columns for the search index, and modify the routing keys of the search index.

Overview

Data tables of Tablestore are schema-free. However, search indexes have rigid schemas. When you create a search index, you must specify the columns you want to add to the search index. Then, you can query these columns when you use the search index to query data. To adapt to business changes and optimize performance, an increasing number of users need to modify the schemas of search indexes. Tablestore allows you to dynamically modify the schemas of search indexes in the following scenarios:
  • Add index columns: You can add index columns if your business requires more columns for queries.
  • Update index columns: Modify the analyzer of a TEXT field.
  • Delete index columns: You may need to remove unnecessary columns added when you create a search index.
  • Modify routing keys: You can specify routing keys to reduce read workloads and improve query efficiency.
The following process describes how to dynamically modify a schema with ease. The whole process does not affect business. You do not need to change business code.
  1. Create a grayscale index on a data table. Add, modify, or remove the schema of a search index.
  2. Wait until the existing and incremental data of the data table is synchronized to the grayscale index and the synchronization progress is the same as that of the search index.
  3. Use A/B testing to make sure that traffic is gradually directed to the grayscale index. Wait until all traffic is switched to the grayscale index.
  4. After you verify that the grayscale index works normally, switch the schemas between the source index and the grayscale index.
  5. Delete the source index schema.

Procedure

  1. Go to the Indexes tab.
    1. Log on to the Tablestore console.
    2. On the Overview page, click the name of the required instance or click Manage Instance in the Actions column that corresponds to the instance.
    3. In the Tables section of the Instance Details tab, click the name of the data table and then click the Indexes tab. You can also click Indexes in the Actions column that corresponds to the data table.
  2. Create a grayscale index based on the source index.
    1. On the Indexes tab, click Change Schema in the Actions column that corresponds to the search index.
    2. In the Reindex dialog box, add, modify, or delete index fields.
      fig_indexmanagement
    3. Click OK.
    4. In the Compare Schemas message, compare the schema information between the source index and the grayscale index. After you confirm the information, click OK.
  3. View the index synchronization information.
    The existing data synchronization and incremental data synchronization stages are required for the grayscale index. Before data is synchronized, the system displays Yes, but the operation may cause security risks. In this case, you cannot perform the switchover. When the synchronization progress of the grayscale index is the same as that of the source index, the system displays Yes. The operation is secure. You can perform subsequent operations. fig_huidu_online
    1. Click the fig_collospe icon in front of the source index or click the name of the source index.
      The system displays the grayscale index of the source index.
    2. Click Use Gray Index in the Actions column that corresponds to the grayscale index.
    3. In the Use Gray Index dialog box, view the synchronization information of the indexes.
  4. After data is synchronized for the indexes, set weights to perform A/B testing.
    A/B testing allows you to allocate traffic to the source index and the grayscale index based on proportions and verify the effects of changes to the schema. You can perform subsequent operations only when all traffic is directed to the grayscale index.
    1. In the Operations section of the Use Gray Index dialog box, adjust the slider to control the weights for the source index and the grayscale index. Click Set Weight.
      fig_setindex
    2. In the Set Weight dialog box, view the weight data and the schema comparison information.
    3. After you confirm the information, click Set Weight.
    4. In the message that appears, click OK.
  5. After all traffic for queries is directed to the grayscale index, switch the schemas between the source index and the grayscale index.
    After you switch the schemas, the name of the source index is associated with the new schema. The name of the grayscale index is associated with the source index schema. All traffic is directed to query the new schema associated with the source index name. fig_exchangeindex
    1. In the Operations section of the Use Gray Index dialog box, click Switch Index.
    2. In the Switch Index dialog box, check the schema information of the source index and the grayscale index. Click Confirm Switch.
  6. You can delete the source index schema after you verify that new schema is correct. To delete the source index schema, we recommend that you wait for a period of time such as one day.
    In the Use Gray Index dialog box, click Delete Source Search Index. You can delete the source index schema. fig_deleteindex

Security

To prevent incorrect operations, Tablestore provides the rollback mechanism and switchover notes to minimize the risks caused by modifying schemas.
  • Rollback mechanism
    When you dynamically modify the schema of a search index, you can roll back the modification.
    • After you create a grayscale index, you can delete the grayscale index and create a grayscale index if the schema of the grayscale index does not meet your expectations.
    • When you perform A/B testing, you can configure weights to gradually direct traffic to the grayscale index. In this process, you can reset the weights anytime to direct traffic back to the source index if you find issues.
    • After you switch the schemas between the source index and the grayscale index, you can cancel the switchover anytime to switch back the schemas if you find issues. Index switchover is the reverse of switchover cancellation.
  • Switchover notes

    If you switch traffic to a grayscale index when the synchronization progress of the grayscale index is slower than that of the source index, the data you query may not be the latest. At this time, Tablestore determines whether to switch indexes based on the synchronization status and the last synchronization time of the source index and the grayscale index.

    If the following situations exist, Tablestore determines that the indexes can be switched:
    • The source index is in the full data synchronization stage. The grayscale index is in the full or incremental data synchronization stage. The synchronization progress of the grayscale index is the same as that of the source index.
    • The source index and the grayscale index are in the incremental data synchronization stage. The last synchronization time of the source index is at most 60 seconds earlier than that of the grayscale index.