• 清空表
可以使用 TRUNCATE TABLE SQL 语句或 PHP 客户端函数 truncate() 来清空表。
以下是 SQL 语句的语法:
TRUNCATE TABLE index_name [WITH RECONFIGURE]执行此语句时,它会完全清空实时表(RT 表)。它会清除内存中的数据,解除所有表数据文件的链接,并释放相关的二进制日志。
也可以使用 DELETE FROM index WHERE id>0 来清空表,但不推荐这种方法,因为它比 TRUNCATE 慢。
SQL:
TRUNCATE TABLE products;Query OK, 0 rows affected (0.02 sec)JSON:
POST /cli -d "TRUNCATE TABLE products"{
"total":0,
"error":"",
"warning":""
}PHP:
$params = [ 'index' => 'products' ];
$response = $client->indices()->truncate($params);Array(
[total] => 0
[error] =>
[warning] =>
)Python:
utilsApi.sql('TRUNCATE TABLE products'){u'error': u'', u'total': 0, u'warning': u''}Javascript:
res = await utilsApi.sql('TRUNCATE TABLE products');{"total":0,"error":"","warning":""}java:
utilsApi.sql("TRUNCATE TABLE products");{total=0, error=, warning=}C#:
utilsApi.Sql("TRUNCATE TABLE products");{total=0, error="", warning=""}此命令的一个可能用途是在附加表之前使用。
当使用 RECONFIGURE 选项时,配置中指定的新标记化、词法分析和其他文本处理设置会在表被清空后生效。如果配置中的模式声明与表模式不同,则清空表后会应用配置中的新模式。
使用此选项,清空和重新配置表将成为一个原子操作。
SQL:
TRUNCATE TABLE products with reconfigure;Query OK, 0 rows affected (0.02 sec)JSON:
POST /cli -d "TRUNCATE TABLE products with reconfigure"{
"total":0,
"error":"",
"warning":""
}PHP:
$params = [ 'index' => 'products', 'with' => 'reconfigure' ];
$response = $client->indices()->truncate($params);Array(
[total] => 0
[error] =>
[warning] =>
)Python:
utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE'){u'error': u'', u'total': 0, u'warning': u''}Javascript:
res = await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE');{"total":0,"error":"","warning":""}java:
utilsApi.sql("TRUNCATE TABLE products WITH RECONFIGURE");{total=0, error=, warning=}C#:
utilsApi.Sql("TRUNCATE TABLE products WITH RECONFIGURE");{total=0, error="", warning=""}最后更新于