/manual/Emptying_an_index.md

https://github.com/manticoresoftware/manticoresearch · Markdown · 125 lines · 92 code · 33 blank · 0 comment · 0 complexity · eb05484c29ada45770fc5af599f3ea23 MD5 · raw file

  1. # Emptying an index
  2. The index can be emptied with a `TRUNCATE TABLE` SQL statement or with a `truncate()` PHP client function.
  3. Here is the syntax for the SQL statement:
  4. ```sql
  5. TRUNCATE TABLE index_name [WITH RECONFIGURE]
  6. ```
  7. <!-- example truncate -->
  8. 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.
  9. 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`.
  10. <!-- intro -->
  11. ##### SQL:
  12. <!-- request SQL -->
  13. ```sql
  14. truncate table products;
  15. ```
  16. <!-- response SQL -->
  17. ```sql
  18. Query OK, 0 rows affected (0.02 sec)
  19. ```
  20. <!-- intro -->
  21. ##### HTTP:
  22. <!-- request HTTP -->
  23. ```http
  24. POST /sql -d "mode=raw&query=truncate table products"
  25. ```
  26. <!-- response HTTP -->
  27. ```http
  28. {
  29. "total":0,
  30. "error":"",
  31. "warning":""
  32. }
  33. ```
  34. <!-- intro -->
  35. ##### PHP:
  36. <!-- request PHP -->
  37. ```php
  38. $params = [ 'index' => 'products' ];
  39. $response = $client->indices()->truncate($params);
  40. ```
  41. <!-- response PHP -->
  42. ```php
  43. Array(
  44. [total] => 0
  45. [error] =>
  46. [warning] =>
  47. )
  48. ```
  49. <!-- end -->
  50. One of the possible uses of this command is before [attaching an index](Adding_data_from_external_storages/Adding_data_from_indexes/Attaching_a_plain_index_to_RT_index.md).
  51. <!-- example truncate with RECONFIGURE -->
  52. 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.
  53. <!-- intro -->
  54. ##### SQL:
  55. <!-- request SQL -->
  56. ```sql
  57. truncate table products with reconfigure;
  58. ```
  59. <!-- response SQL -->
  60. ```sql
  61. Query OK, 0 rows affected (0.02 sec)
  62. ```
  63. <!-- intro -->
  64. ##### HTTP:
  65. <!-- request HTTP -->
  66. ```http
  67. POST /sql -d "mode=raw&query=truncate table products with reconfigure"
  68. ```
  69. <!-- response HTTP -->
  70. ```http
  71. {
  72. "total":0,
  73. "error":"",
  74. "warning":""
  75. }
  76. ```
  77. <!-- intro -->
  78. ##### PHP:
  79. <!-- request PHP -->
  80. ```php
  81. $params = [ 'index' => 'products', 'with' => 'reconfigure' ];
  82. $response = $client->indices()->truncate($params);
  83. ```
  84. <!-- response PHP -->
  85. ```php
  86. Array(
  87. [total] => 0
  88. [error] =>
  89. [warning] =>
  90. )
  91. ```
  92. <!-- end -->