Todos os produtos
Search
Central de documentação

Tablestore:Atualizar configurações de índice de pesquisa

Última atualização: Jun 30, 2026

Use a operação UpdateSearchIndex no Tablestore SDK for Python para atualizar o tempo de vida (TTL) de um índice de pesquisa.

Pré-requisitos

Verifique se você concluiu as seguintes preparações:

Observações de uso

  • O TTL do índice de pesquisa é independente do TTL da tabela de dados, mas não pode excedê-lo.

  • Para reduzir o TTL, altere primeiro o valor do índice de pesquisa e, em seguida, o da tabela de dados.

  • O Tablestore exclui automaticamente os dados expirados dos índices de pesquisa uma vez por dia. Esses dados permanecem consultáveis até o próximo ciclo de exclusão.

  • Após a atualização do TTL, o Tablestore remove os dados históricos expirados no ciclo diário seguinte.

Parâmetros

Parâmetro

Obrigatório

Descrição

table_name

Sim

Nome da tabela de dados.

index_name

Sim

Nome do índice de pesquisa.

time_to_live

Sim

TTL do índice de pesquisa em segundos. Defina como -1 para que os dados nunca expirem ou utilize um valor int32 positivo. O valor máximo de int32 equivale a aproximadamente 68 anos.

Exemplos

O exemplo a seguir define o TTL do índice de pesquisa como sete dias:

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)

Verificar a atualização

Após atualizar o TTL, chame describe_search_index para confirmar a alteração:

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)

Desativar o TTL

Para desativar o TTL e garantir que os dados nunca expirem, defina time_to_live como -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)

Perguntas frequentes

[O que fazer se a mensagem de erro [table ttl] must be bigger than or equal search index ttl for retornada ao modificar o TTL de uma tabela de dados?](t2633375.xdita#)

Referências