我想从ElasticSearch中删除数据。我已经删除了索引。然而,这似乎并没有真正删除数据本身。我看到的其他东西指向通过查询删除功能。然而,我甚至不知道该问什么。我知道指数。本质上,我想知道如何做a

DELETE FROM [Index]

从邮递员在Chrome。然而,我没有任何运气。似乎无论我做什么,数据都不会消失。到目前为止,我已经成功地删除索引使用DELETE HTTP动词在邮差和使用一个url:

   http://localhost:9200/[indexName]

然而,这似乎并没有真正删除数据(又名文档)本身。


当前回答

删除所有索引的python脚本:

import requests
import json

ES_HOST = "http://localhost:9200"
ES_URL = f"{ES_HOST}/_cat/indices?format=json"

indexes = requests.get(ES_URL).content
indexes = json.loads(index.decode())

for i in index:
    index_name = i['index']
    content = requests.delete(f"{ES_HOST}/{index_name}").content
    print(content)

其他回答

1. 删除火

从指定索引中移除文档。

DELETE /<index>/_doc/<_id>

例子:

DELETE http://localhost:9200/my-index-000001/_doc/1

参考:ES指南>>删除API

2. 通过查询API删除

删除与指定查询匹配的文档。

例子:

POST http://localhost:9200/my-index-000001/_delete_by_query
{
  "query": {
      "match": {
           "user.id": "elkbee"
      }
   }
}

参考:ES指南>>根据查询API删除

我想删除logstash索引,并搜索了很多关于不同的工具,如curl。但最后找到了解决方案。 登录到Kibana。进入开发工具选项卡,在查询字段中输入DELETE /logstash-*,然后点击绿色箭头按钮。如果你得到“acknowledge”:true作为响应,这意味着数据已经被清除。

在python中可以这样删除索引

from elasticsearch import Elasticsearch

es = Elasticsearch([{'host':'localhost', 'port':'9200'}])

es.index(index='grades',doc_type='ist_samester',id=1,body={
    "Name":"Programming Fundamentals",
    "Grade":"A"
})

es.indices.delete(index='grades')

假设我需要删除索引filebeat-7.6.2-2020.04.30-000001,我使用curl delete选项执行它(curl -X delete "localhost:9200/filebeat-7.6.2-2020.04.30-000001?pretty"),并导致如下所示的身份验证问题;

{
  "error" : {
    "type" : "security_exception",
    "reason" : "missing authentication credentials for REST request [/filebeat-7.6.2-2020.04.30-000001?pretty]"
  },
  "status" : 401
}

在这里,您应该使用为Elasticsearch提供的用户名和密码对curl请求进行身份验证。然后试着

curl -X DELETE -u myelasticuser:myelasticpassword "localhost:9200/filebeat-7.6.2-2020.04.30-000001?漂亮”

将导致{ “acknowledge”:正确 }。

对于批量按查询删除,你可以使用特殊的按查询删除API:

$ curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d '{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

在历史上,该API被删除,然后又重新引入

谁有趣,它有悠久的历史。

在这个答案的第一个版本中,我参考了elasticsearch版本1.6的文档。在这篇文章中,该功能被标记为已弃用,但运行良好。 在elasticsearch 2.0版本中,它被移动到单独的插件中。甚至解释了为什么它成为插件的原因。 它再次出现在5.0版的核心API中!