侧边栏壁纸
博主头像
福福不服博主等级

孩子会穿过大雨,去懂人间的道理。

  • 累计撰写 93 篇文章
  • 累计创建 101 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Elasticsearch删除文档

Monster
2023-08-02 / 0 评论 / 6 点赞 / 84 阅读 / 3690 字 / 正在检测是否收录...
温馨提示:
请确保在评论和互动中保持礼貌和尊重。避免使用侮辱性、歧视性或攻击性语言。我们鼓励建设性的讨论和意见交流。

Elasticsearch删除文档

根据id删除

例如删除id为110的文档

DELETE /ffbf/_doc/110

返回信息

{
  "_index" : "ffbf",
  "_type" : "_doc",
  "_id" : "110",
  "_version" : 4,
  "result" : "deleted",
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "_seq_no" : 5,
  "_primary_term" : 1
}

根据查询条件删除_delete_by_query

例如删除name叫Helen的的文档

DELETE /ffbf/_doc/110

POST /ffbf/_delete_by_query
{
  "query":{
    "match": {
      "name":"Helen"
    }
  }
}

返回信息,有两个文档被删了

{
  "took" : 465,
  "timed_out" : false,
  "total" : 2,
  "deleted" : 2,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

使用range根据范围删除

age大雨130,小雨140的文档

POST /ffbf/_delete_by_query
{
  "query":{
    "range": {
      "age":{
        "gt":130,
        "lt":140
      }
    }
  }
}

返回信息,又一个文档被删了

{
  "took" : 913,
  "timed_out" : false,
  "total" : 1,
  "deleted" : 1,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

删除索引下的所有文档

删除ffbf索引下的所有文档

POST /ffbf/_delete_by_query
{
  "query":{
    "match_all": {}
  }
}

返回信息,只剩下一个文档了,也被删除了

{
  "took" : 1779,
  "timed_out" : false,
  "total" : 1,
  "deleted" : 1,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

删除多个索引下的文档

例如:同时删除ffbf、qqbq索引的的所有文档

ffbf已经被删除所有文档了,qqbq索引前面创建过一个文档,应该只有一个响应

POST ffbf,qqbq/_delete_by_query
{
  "query":{
    "match_all": {}
  }
}

返回信息,deleted:1

{
  "took" : 89,
  "timed_out" : false,
  "total" : 1,
  "deleted" : 1,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

查看索引情况

GET /_cat/indices?v

返回信息,qqbq、ffbf的docs.count都为0了

health status index                           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .apm-custom-link                Xmj6MPxBT_ipIOZyTbwCQw   1   1          0            0       416b           208b
green  open   .kibana_task_manager_1          RmlBFYfNRSSXXJzlmMf8aA   1   1          5        65767     10.6mb          5.3mb
green  open   .apm-agent-configuration        QFeI8NB1R8OeOnSy51Z92w   1   1          0            0       416b           208b
green  open   .kibana-event-log-7.10.1-000001 p-r29FQyT6KWlM4C_hvIMw   1   1          2            0       22kb           11kb
green  open   qqbq                            lVGlJpM0RXOrA8WfhMauTA   1   1          0            0      6.5kb          3.2kb
green  open   ffbf                            7zMVV6IrQt6KrZBdIi26bw   2   2          0            0     37.2kb         16.8kb
green  open   .kibana_1                       9JoNLVfYTsaxpsYufqKI7g   1   1         60           46      8.5mb          4.2mb
6
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin
  3. QQ打赏

    qrcode qq

评论区