All Products
Search
Document Center

Tablestore:Update search index configurations

Last Updated:Feb 27, 2026

Update the time to live (TTL) of a search index by calling the UpdateSearchIndex operation in Tablestore SDK for Python.

Prerequisites

Before you begin, ensure that you have:

Usage notes

  • The search index TTL is independent of the data table TTL but must be less than or equal to it.

  • To decrease the TTL, change the search index TTL first, then the data table TTL.

  • Tablestore automatically deletes expired data from search indexes once per day. Expired data remains queryable until the next deletion cycle runs.

  • After you update the TTL, Tablestore deletes historical expired data in the next daily cycle.

Parameters

ParameterRequiredDescription
table_nameYesThe name of the data table.
index_nameYesThe name of the search index.
time_to_liveYesThe TTL of the search index in seconds. Set to -1 so that data never expires, or set to a positive int32 value. The maximum int32 value is equivalent to approximately 68 years.

Examples

Set the search index TTL to seven days:

import os
from tablestore import OTSClient
from tablestore.metadata import SearchIndexMeta

# Initialize the client with environment variable credentials
client = OTSClient(
    end_point=os.environ["OTS_ENDPOINT"],
    access_key_id=os.environ["OTS_ACCESS_KEY_ID"],
    access_key_secret=os.environ["OTS_ACCESS_KEY_SECRET"],
    instance_name=os.environ["OTS_INSTANCE"],
)

TABLE_NAME = "<TABLE_NAME>"
INDEX_NAME = "<SEARCH_INDEX_NAME>"

def update_search_index_ttl(client, table_name, index_name, ttl_seconds):
    """Update the TTL of a search index.

    Args:
        client: An initialized OTSClient instance.
        table_name: The name of the data table.
        index_name: The name of the search index.
        ttl_seconds: TTL in seconds. Use -1 for no expiration.
    """
    # Set fields to None because only the TTL is being updated
    index_meta = SearchIndexMeta(fields=None, time_to_live=ttl_seconds)
    client.update_search_index(table_name, index_name, index_meta)
    print(f"Search index TTL updated to {ttl_seconds} seconds.")

# Set TTL to 7 days (in seconds)
seven_days = 24 * 3600 * 7
update_search_index_ttl(client, TABLE_NAME, INDEX_NAME, seven_days)

Verify the update

After updating the TTL, call describe_search_index to confirm the change:

def verify_search_index_ttl(client, table_name, index_name):
    """Print the current TTL of a search index."""
    index_meta, sync_stat = client.describe_search_index(table_name, index_name)
    print(f"Current TTL: {index_meta.time_to_live} seconds")

verify_search_index_ttl(client, TABLE_NAME, INDEX_NAME)

Disable TTL

To disable TTL so that data never expires, set time_to_live to -1:

# Disable TTL (data never expires)
index_meta = SearchIndexMeta(fields=None, time_to_live=-1)
client.update_search_index(TABLE_NAME, INDEX_NAME, index_meta)

FAQ

What do I do if the [table ttl] must be bigger than or equal search index ttl error message is returned when I modify the TTL of a data table?

References