Link Search Menu Expand Document Documentation Menu

删除

DELETE 语句删除满足 WHERE 子句中谓词的文档。如果未指定 WHERE 子句,则会删除所有文档。

设置

DELETE 语句默认是禁用的。要在 SQL 中启用 DELETE 功能,您需要通过发送以下请求来更新配置

PUT _plugins/_query/settings
{
  "transient": {
    "plugins.sql.delete.enabled": "true"
  }
}

语法

规则 singleDeleteStatement

singleDeleteStatement

示例

SQL 查询

DELETE FROM accounts
WHERE age > 30

解释

{
  "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
}

结果集

{
  "schema" : [
    {
      "name" : "deleted_rows",
      "type" : "long"
    }
  ],
  "total" : 1,
  "datarows" : [
    [
      3
    ]
  ],
  "size" : 1,
  "status" : 200
}

datarows 字段显示已删除的文档数量。

剩余 350 字符

有问题?

想做贡献?