Updates the time to live (TTL) of a search index using Tablestore SDK for Node.js by calling the UpdateSearchIndex operation.
Prerequisites
-
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
-
A search index exists for the data table.
-
The
allowUpdateparameter is set tofalsefor the data table. For more information, see Update the configurations of a table.
Usage notes
When you configure the TTL for a search index, take note of the following items:
-
The TTL of the data table and the TTL of the search index are independent of each other. The TTL of the search index cannot exceed the TTL of the data table. If you want to shorten the TTL of both the data table and the search index at the same time, update the TTL of the search index before you update the TTL of the data table.
-
The search index clears expired data on a daily basis. After data expires and before the next clearing task is run, the data may still be returned in queries.
-
After you shorten the TTL, the system deletes the expired historical data in subsequent clearing tasks.
Parameters
|
Parameter |
Description |
|
tableName (required) |
The name of the data table. |
|
indexName (required) |
The name of the search index. |
|
timeToLive (required) |
The TTL of the search index, in seconds. Set to |
Examples
The following example sets the TTL of a search index to seven days (604,800 seconds):
let params = {
tableName: '<TABLE_NAME>',
indexName: '<SEARCH_INDEX_NAME>',
timeToLive: 604800, // 7 days in seconds (7 x 24 x 60 x 60)
}
client.updateSearchIndex(params, function (err, data) {
if (err) {
console.log('updateSearchIndex error:', err.toString());
} else {
console.log('updateSearchIndex success:', data);
}
});
To calculate the timeToLive value for a different duration, multiply the number of days by 86400 (seconds per day). For example, 30 days is 2592000.
FAQ
References
-
For information about the TTL of a search index, see Specify the TTL of a search index.
-
To query the fields and schema of a search index, see Query the description of a search index.
-
To add, update, or remove index columns or change the routing key and presorting method, see Dynamically modify the schema of a search index.