全部產品
Search
文件中心

Tablestore:更新多元索引配置

更新時間:Aug 06, 2026

使用 Python SDK 更新多元索引的資料生命週期。

前提條件

  • 安裝Tablestore Python SDK並初始化用戶端。

  • 資料表已禁止通過 UpdateRow 更新資料,即 allow_update 為 False。有關設定方法,請參見更新表配置。

功能說明

調用 update_search_index 方法更新指定多元索引的資料生命週期。

def update_search_index(
    self,
    table_name,
    index_name,
    index_meta,
)
重要

配置生命週期時,注意以下事項:

  • Python SDK 的 update_search_index 方法僅支援更新生命週期,不能修改索引欄位、索引設定或預排序設定。

  • 資料表和多元索引的生命週期相互獨立,多元索引的生命週期不能超過資料表的生命週期。如果需要將多元索引的生命週期調大到超過資料表當前生命週期,請先調巨量資料表生命週期;如果需要將資料表生命週期調小到低於多元索引當前生命週期,請先調小多元索引生命週期。

  • Tablestore 每天清理一次多元索引中的到期資料。資料到期後、下次清理前,查詢仍可能返回這些資料。縮短生命週期後,系統會在後續清理任務中刪除已到期的存量資料。

以下樣本將 example_table 中 example_index 的生命週期更新為 7 天,並查詢更新後的值。

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)

參數說明

update_search_index 方法包含以下參數。

名稱

類型

說明

table_name(必選)

str

資料表名稱。

index_name(必選)

str

多元索引名稱。

index_meta(必選)

SearchIndexMeta

要更新的多元索引配置。

索引配置

index_meta 的類型為 SearchIndexMeta,更新生命週期時使用以下參數。

名稱

類型

說明

fields(必選)

List[FieldSchema]

固定設定為 None。更新要求不會修改索引欄位。

time_to_live(可選)

int

索引資料的生命週期,單位為秒,預設值為 -1。取值為 -1 或 int32 範圍內的正整數;-1 表示資料永不到期,最大值約為 68 年。

情境樣本

關閉生命週期

將 time_to_live 設定為 -1,使多元索引中的資料永不到期。

index_meta = SearchIndexMeta(fields=None, time_to_live=-1)
client.update_search_index(
    "example_table",
    "example_index",
    index_meta,
)