After you create a search index, you can call the UpdateSearchIndex operation to update the configurations of the search index. This topic describes how to use Tablestore SDK for PHP to update the time to live (TTL) of a search index.
Prerequisites
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A search index is created for a data table.
The
allow_update
parameter is set tofalse
for the data table. For more information, see Update the configurations of a table.
Usage notes
The TTL of a search index is independent of and must be no greater than that of the data table for which the search index is created. If you want to decrease the TTL of a search index and the data table for which the search index is created, you must change the TTL of the search index before you change the TTL of the data table.
Tablestore automatically deletes expired data from search indexes every day. You can still query expired data in search indexes before the expired data is deleted. Tablestore automatically deletes the expired data in the next cycle.
After you change the TTL of data tables and search indexes, Tablestore automatically deletes the historical expired data from the data tables and search indexes in the next cycle.
Parameters
Parameter | Description |
table_name (required) | The name of the data table. |
index_name (required) | The name of the search index. |
time_to_live (required) | The TTL of the search index. The TTL of a search index must be -1 or a positive int32 value in seconds. A value of -1 specifies that data in the search index never expires, and the maximum int32 value is equivalent to approximately 68 years. |
Examples
The following sample code provides an example on how to change the TTL of a search index to seven days:
$response = $otsClient->updateSearchIndex(array(
'table_name' => 'php_sdk_test',
'index_name' => 'test_create_search_index',
'time_to_live' => 60 * 60 * 24 * 7 // Unit: seconds.
));
print json_encode($response, JSON_PRETTY_PRINT);
FAQ
References
For information about the TTL of a search index, see Specify the TTL of a search index.
You can query the detailed information about a search index, such as the fields and schema of the search index. For more information, see Query the description of a search index.
You can dynamically modify the schema of a search index to add, update, or remove index columns in the search index or change the routing key and presorting method of the search index. For more information, see Dynamically modify the schema of a search index.