Emptying an index

The index can be emptied with a TRUNCATE TABLE SQL statement or with a truncate() PHP client function.

Here is the syntax for the SQL statement:

TRUNCATE TABLE index_name [WITH RECONFIGURE]

When this statement is executed, it clears the RT index completely. It disposes the in-memory data, unlinks all the index data files, and releases the associated binary logs.

An index can also be emptied with DELETE FROM index WHERE id>0, but it's not recommended as it's much slower than TRUNCATE.

‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
TRUNCATE TABLE products;
‹›
Response
Query OK, 0 rows affected (0.02 sec)

One of the possible uses of this command is before attaching an index.

When RECONFIGURE option is used new tokenization, morphology, and other text processing settings specified in the config take effect after the index gets cleared. With this option clearing and reconfiguring an index becomes one atomic operation.

‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
TRUNCATE TABLE products with reconfigure;
‹›
Response
Query OK, 0 rows affected (0.02 sec)