Emptying a table

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

Here is the syntax for the SQL statement:

  1. TRUNCATE TABLE index_name [WITH RECONFIGURE]

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

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

  • SQL
  • JSON
  • PHP
  • Python
  • javascript
  • Java

SQL JSON PHP Python javascript Java

  1. TRUNCATE TABLE products;
  1. POST /cli -d "TRUNCATE TABLE products"
  1. $params = [ 'index' => 'products' ];
  2. $response = $client->indices()->truncate($params);
  1. utilsApi.sql('TRUNCATE TABLE products')
  1. res = await utilsApi.sql('TRUNCATE TABLE products');
  1. utilsApi.sql("TRUNCATE TABLE products");

Response

  1. Query OK, 0 rows affected (0.02 sec)
  1. {
  2. "total":0,
  3. "error":"",
  4. "warning":""
  5. }
  1. Array(
  2. [total] => 0
  3. [error] =>
  4. [warning] =>
  5. )
  1. {u'error': u'', u'total': 0, u'warning': u''}
  1. {"total":0,"error":"","warning":""}
  1. {total=0, error=, warning=}

One of the possible uses of this command is before attaching a table.

When RECONFIGURE option is used new tokenization, morphology, and other text processing settings specified in the config take effect after the table gets cleared. In case the schema declaration in config is different from the table schema the new schema from config got applied after table get cleared.

With this option clearing and reconfiguring a table becomes one atomic operation.

  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java

SQL HTTP PHP Python javascript Java

  1. TRUNCATE TABLE products with reconfigure;
  1. POST /cli -d "TRUNCATE TABLE products with reconfigure"
  1. $params = [ 'index' => 'products', 'with' => 'reconfigure' ];
  2. $response = $client->indices()->truncate($params);
  1. utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE')
  1. res = await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE');
  1. utilsApi.sql("TRUNCATE TABLE products WITH RECONFIGURE");

Response

  1. Query OK, 0 rows affected (0.02 sec)
  1. {
  2. "total":0,
  3. "error":"",
  4. "warning":""
  5. }
  1. Array(
  2. [total] => 0
  3. [error] =>
  4. [warning] =>
  5. )
  1. {u'error': u'', u'total': 0, u'warning': u''}
  1. {"total":0,"error":"","warning":""}
  1. {total=0, error=, warning=}

Manticore cluster

Manticore Search is a highly distributed system and consists of all the needed components to allow you build a highly available and scalable setup of a database for search:

Manticore Search is extremely flexible in terms of how you setup your cluster, there’s no limitations and it’s up to you how you design it. Just learn the tools mentioned above and use them to achieve your goal.

Adding a new node

To add another node to a cluster just start another node of Manticore and make sure it’s accessible by other nodes in your cluster. Then use a distributed table to connect one node with another and replication for data safety.