Deleting documents is only supported for the following table types: * Real-time tables, * Percolate tables, * Distributed tables that only contain RT tables a local or remote agents.
You can delete existing documents from a table based on either their ID or certain conditions.
Deletion of documents can be accomplished via both SQL and HTTP interfaces.
For SQL, the response for a successful operation will indicate the number of rows deleted.
For HTTP, the json/delete
endpoint is used. The server will respond with a JSON object indicating whether the operation was successful and the number of rows deleted.
It is recommended to use table truncation instead of deletion to delete all documents from a table, as it is a much faster operation.
DELETE FROM table WHERE where_condition
table
is a name of the table from which the row should be deleted.where_condition
for SQL has the same syntax as in the SELECT statement.POST /delete -d '
{
"index": "test",
"id": 1
}'
POST /delete -d '
{
"index": "test",
"query":
{
"match": { "*": "apple" }
}
}'
id
for JSON is the row id
which should be deleted.query
for JSON is the full-text condition and has the same syntax as in the JSON/update.cluster
for JSON is cluster name property and should be set along with table
property to delete a row from a table which is inside a replication cluster.In this example we are deleting all documents that match full-text query dummy
from table named test
:
SELECT * FROM TEST;
DELETE FROM TEST WHERE MATCH ('dummy');
SELECT * FROM TEST;
+------+------+-------------+------+
id | gid | mva1 | mva2 |
| +------+------+-------------+------+
100 | 1000 | 100,201 | 100 |
| 101 | 1001 | 101,202 | 101 |
| 102 | 1002 | 102,203 | 102 |
| 103 | 1003 | 103,204 | 103 |
| 104 | 1004 | 104,204,205 | 104 |
| 105 | 1005 | 105,206 | 105 |
| 106 | 1006 | 106,207 | 106 |
| 107 | 1007 | 107,208 | 107 |
| +------+------+-------------+------+
8 rows in set (0.00 sec)
Query OK, 2 rows affected (0.00 sec)
+------+------+-------------+------+
id | gid | mva1 | mva2 |
| +------+------+-------------+------+
100 | 1000 | 100,201 | 100 |
| 101 | 1001 | 101,202 | 101 |
| 102 | 1002 | 102,203 | 102 |
| 103 | 1003 | 103,204 | 103 |
| 104 | 1004 | 104,204,205 | 104 |
| 105 | 1005 | 105,206 | 105 |
| +------+------+-------------+------+
6 rows in set (0.00 sec)
POST /delete -d '
{
"index":"test",
"query":
{
"match": { "*": "dummy" }
}
}'
{
"_index":"test",
"deleted":2,
}
$index->deleteDocuments(new Match('dummy','*'));
Array(
[_index] => test
[deleted] => 2
)
"index" : "products", "query": { "match": { "*": "dummy" }}}) indexApi.delete({
'deleted': 2, 'id': None, 'index': 'products', 'result': None} {
= await indexApi.delete({"index" : "products", "query": { "match": { "*": "dummy" }}}); res
"_index":"products","deleted":2} {
new DeleteDocumentRequest();
DeleteDocumentRequest deleteRequest = new HashMap<String,Object>();
query = put("match",new HashMap<String,Object>(){{
query.put("*","dummy");
}});index("products").setQuery(query);
deleteRequest.delete(deleteRequest); indexApi.
class DeleteResponse {
index: products2
deleted: null
id: null
result: }
Here - deleting a document with id
100 from table named test
:
DELETE FROM TEST WHERE id=100;
SELECT * FROM TEST;
Query OK, 1 rows affected (0.00 sec)
+------+------+-------------+------+
id | gid | mva1 | mva2 |
| +------+------+-------------+------+
101 | 1001 | 101,202 | 101 |
| 102 | 1002 | 102,203 | 102 |
| 103 | 1003 | 103,204 | 103 |
| 104 | 1004 | 104,204,205 | 104 |
| 105 | 1005 | 105,206 | 105 |
| +------+------+-------------+------+
5 rows in set (0.00 sec)
POST /delete -d '
{
"index":"test",
"id": 100
}'
{
"_index":"test",
"_id":100,
"found":true,
"result":"deleted"
}
$index->deleteDocument(100);
Array(
[_index] => test
[_id] => 100
[found] => true
[result] => deleted
)
"index" : "products", "id" : 1}) indexApi.delete({
'deleted': None, 'id': 1, 'index': 'products', 'result': 'deleted'} {
= await indexApi.delete({"index" : "products", "id" : 1}); res
"_index":"products","_id":1,"result":"deleted"} {
new DeleteDocumentRequest();
DeleteDocumentRequest deleteRequest = index("products").setId(1L);
deleteRequest.delete(deleteRequest); indexApi.
class DeleteResponse {
index: products1
_id:
result: deleted }
Manticore SQL allows to use complex conditions for the DELETE
statement.
For example here we are deleting documents that match full-text query dummy
and have attribute mva1
with a value greater than 206 or mva1
values 100 or 103 from table named test
:
DELETE FROM TEST WHERE MATCH ('dummy') AND ( mva1>206 or mva1 in (100, 103) );
SELECT * FROM TEST;
Query OK, 4 rows affected (0.00 sec)
+------+------+-------------+------+
id | gid | mva1 | mva2 |
| +------+------+-------------+------+
101 | 1001 | 101,202 | 101 |
| 102 | 1002 | 102,203 | 102 |
| 104 | 1004 | 104,204,205 | 104 |
| 105 | 1005 | 105,206 | 105 |
| +------+------+-------------+------+
6 rows in set (0.00 sec)
Here is an example of deleting documents in cluster cluster
’s table test
:
delete from cluster:test where id=100;
POST /delete -d '
{
"cluster":"cluster",
"index":"test",
"id": 100
}'
$index->setCluster('cluster');
$index->deleteDocument(100);
Array(
[_index] => test
[_id] => 100
[found] => true
[result] => deleted
)
"cluster":"cluster","index" : "products", "id" : 100}) indexApi.delete({
'deleted': None, 'id': 100, 'index': 'products', 'result': 'deleted'} {
.delete({"cluster":"cluster","index" : "products", "id" : 100}) indexApi
"_index":"products","_id":100,"result":"deleted"} {
new DeleteDocumentRequest();
DeleteDocumentRequest deleteRequest = cluster("cluster").index("products").setId(100L);
deleteRequest.delete(deleteRequest); indexApi.
class DeleteResponse {
index: products100
_id:
result: deleted }