Use the Tablestore SDK for Go to configure the TTL for a new or existing search index and adjust the table TTL when needed.
Prerequisites
Install the Tablestore SDK for Go and initialize a client.
Considerations
The search index TTL is -1 or an int32 integer no less than 86,400 seconds. -1 indicates that data never expires. For a value other than -1, updates by using UpdateRow must be disabled, and the index TTL cannot exceed the table TTL. Expired data is asynchronously removed in the background.
Procedure
The complete workflow includes disabling UpdateRow updates, configuring the search index TTL, and adjusting the table TTL when needed. The order depends on the target values: If the new index TTL exceeds the current table TTL, increase the table TTL first. Otherwise, adjust the table TTL as needed after configuring the index.
1. Disable updates by using UpdateRow
Update the table configuration and set AllowUpdate to false. For more information, see Update table configurations.
2. Configure the search index TTL
New search index
ttl := int32(7 * 24 * 60 * 60)
request := &tablestore.CreateSearchIndexRequest{
TableName: "example_table",
IndexName: "example_index",
TimeToLive: &ttl,
IndexSchema: &tablestore.IndexSchema{
FieldSchemas: []*tablestore.FieldSchema{
{
FieldName: proto.String("category"),
FieldType: tablestore.FieldType_KEYWORD,
Index: proto.Bool(true),
},
},
},
}
_, err := client.CreateSearchIndex(request)
if err != nil {
log.Fatal(err)
}
Existing search index
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)
}
3. Adjust the table TTL when needed
If the table TTL also needs to change, make sure that it is no less than the search index TTL. For more information, see Update table configurations.
Parameters
|
Name |
Type |
Description |
|
TimeToLive (optional) |
*int32 |
The search index TTL in seconds. Valid values are -1 and int32 integers no less than 86,400. -1 indicates that data never expires. Default value when an index is created: -1. |