2021-05-28 10:48:19 -07:00
---
layout: default
title: Delete
parent: SQL
nav_order: 12
---
# Delete
The `DELETE` statement deletes documents that satisfy the predicates in the `WHERE` clause.
If you don't specify the `WHERE` clause, all documents are deleted.
2021-05-24 16:50:29 -07:00
### Setting
The `DELETE` statement is disabled by default. To enable the `DELETE` functionality in SQL, you need to update the configuration by sending the following request:
``` json
2021-08-12 14:34:31 -07:00
P U T _ p l u g i n s / _ q u e r y / s e t t i n g s
2021-05-24 16:50:29 -07:00
{
"transient" : {
"plugins.sql.delete.enabled" : "true"
}
}
```
2021-05-28 10:48:19 -07:00
### Syntax
Rule `singleDeleteStatement` :
2021-06-09 19:15:41 -07:00

2021-05-28 10:48:19 -07:00
### Example
SQL query:
``` sql
DELETE FROM accounts
WHERE age > 30
```
Explain:
``` json
{
"size" : 1000 ,
"query" : {
"bool" : {
"must" : [
{
"range" : {
"age" : {
"from" : 30 ,
"to" : null ,
"include_lower" : false ,
"include_upper" : true ,
"boost" : 1.0
}
}
}
] ,
"adjust_pure_negative" : true ,
"boost" : 1.0
}
} ,
"_source" : false
}
```
Result set:
``` json
{
"schema" : [
{
"name" : "deleted_rows" ,
"type" : "long"
}
] ,
"total" : 1 ,
"datarows" : [
[
3
]
] ,
"size" : 1 ,
"status" : 200
}
```
The `datarows` field shows the number of documents deleted.