Use Tablestore SDK for Python to update the TTL of a search index.
Prerequisites
Install the Tablestore SDK for Python and initialize a client.
The table does not allow
UpdateRowoperations. In other words,allow_updateis set toFalse. For more information, see Update table configurations.
Description
Call update_search_index to update the TTL of a search index.
def update_search_index(
self,
table_name,
index_name,
index_meta,
)
Take note of the following items when you configure a TTL:
The
update_search_indexmethod in Tablestore SDK for Python can update only the TTL. It cannot modify index fields, index settings, or presorting settings.The TTLs of a table and a search index are independent, but the search index TTL cannot exceed the table TTL. To increase the search index TTL beyond the current table TTL, increase the table TTL first. To decrease the table TTL below the current search index TTL, decrease the search index TTL first.
Tablestore deletes expired search index data once a day. Expired data may remain queryable until the next deletion cycle. After you shorten the TTL, Tablestore deletes historical expired data in a subsequent deletion cycle.
The following example updates the TTL of example_index for example_table to seven days and queries the updated value.
index_meta = SearchIndexMeta(
fields=None,
time_to_live=7 * 24 * 60 * 60,
)
client.update_search_index(
"example_table",
"example_index",
index_meta,
)
updated_meta, _ = client.describe_search_index(
"example_table",
"example_index",
)
print(updated_meta.time_to_live)
Parameters
The update_search_index method contains the following parameters.
|
Name |
Type |
Description |
|
table_name (required) |
|
The table name. |
|
index_name (required) |
|
The search index name. |
|
index_meta (required) |
|
The search index configurations to update. |
Search index configurations
index_meta is a SearchIndexMeta object that contains the following parameters for a TTL update.
|
Name |
Type |
Description |
|
fields (required) |
|
Set this parameter to |
|
time_to_live (optional) |
|
The TTL of index data in seconds. Default value: |
Examples
Disable the TTL
Set time_to_live to -1 so that data in the search index does not expire.
index_meta = SearchIndexMeta(fields=None, time_to_live=-1)
client.update_search_index(
"example_table",
"example_index",
index_meta,
)