The time to live (TTL) is an attribute of search indexes that specifies the retention period of data in search indexes. You can specify the TTL of a search index. When data in the search index is retained for a period of time that exceeds the specified TTL, Tablestore automatically deletes the data to free up storage space and reduce costs.
Usage notes
Before you specify the TTL of a search index, you must disable the UpdateRow operation on the data table for which the search index is created. Otherwise, semantic issues may occur.
The specified TTL of a data table takes effect on attribute columns, and the specified TTL of a search index takes effect on the entire rows. If a data table is updated by calling the UpdateRow operation, the values of some fields are deleted and the values of some fields are retained in the data table when Tablestore clears data in the data table. However, the entire rows in the search index that is created for the data table are not deleted. As a result, the data in the data table and search index is inconsistent.
If the data table must be updated, check whether you can call the PutRow operation instead of the UpdateRow operation.
The TTL of a search index can be set to -1 or a positive int32. Unit: seconds. A value of -1 indicates that the data in the search index never expires. The maximum int32 value is equivalent to approximately 68 years.
The TTL of a search index is independent of and must be no greater than that of the data table for which the search index is created. If you need to decrease the TTL of a search index and the data table for which the search index is created, you must change the TTL of the search index before you change the TTL of the data table.
Tablestore automatically deletes expired data from search indexes every day. You can still query expired data in search indexes before the expired data is deleted. Tablestore automatically deletes the expired data in the next cycle.
After you change the TTL of data tables and search indexes, Tablestore automatically deletes the historical expired data from the data tables and search indexes in the next cycle.
Procedures
You can specify the TTL of a search index by using the Tablestore console or Tablestore SDKs. Before you specify the TTL of a search index, you must disable the UpdateRow operation on the data table for which the search index is created.