使用 Tablestore Go SDK 更新多元索引生命週期,或在動態修改 Schema 時調整流量並切換索引。
前提條件
安裝Tablestore Go SDK並初始化用戶端。
功能說明
調用 UpdateSearchIndex 方法更新多元索引的生命週期。動態修改 Schema 時,還可使用該方法設定源索引和灰階索引的查詢流量權重,或交換兩個索引的指向。完整流程請參見動態修改 Schema。
func (client *tablestore.TableStoreClient) UpdateSearchIndex(request *tablestore.UpdateSearchIndexRequest) (*tablestore.UpdateSearchIndexResponse, error)ttl := int32(7 * 24 * 60 * 60)
_, err := client.UpdateSearchIndex(&tablestore.UpdateSearchIndexRequest{
TableName: "example_table",
IndexName: "example_index",
TimeToLive: &ttl,
})
if err != nil {
log.Fatal(err)
}參數說明
名稱 | 類型 | 說明 |
TableName(必選) | string | 資料表名稱。 |
IndexName(必選) | string | 要更新的多元索引名稱。 |
TimeToLive(可選) | *int32 | 索引資料生命週期,單位為秒。取值為 -1 或不小於 86400 的 int32 整數,-1 表示資料永不到期。設定非 -1 值時,必須禁止通過 UpdateRow 更新資料,且索引生命週期不能超過資料表生命週期。更多資訊請參見生命週期管理。 |
QueryFlowWeights(可選) | []*tablestore.QueryFlowWeight | 源索引和灰階索引的查詢流量權重列表。各項 Weight 之和必須為 100。 |
SwitchIndexName(可選) | *string | 要與 IndexName 交換指向的灰階索引名稱。 |
查詢流量權重
名稱 | 類型 | 說明 |
IndexName(必選) | string | 源索引或灰階索引名稱。 |
Weight(必選) | int32 | 查詢流量權重。 |