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

DELETE FROM [Index]

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

   http://localhost:9200/[indexName]

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


当前回答

我使用开发工具删除数据

POST <index_name>/_delete_by_query
  {
   "query": {
       "match_all": {}
    }
 }

例子

POST vehicle-data/_delete_by_query
      {
       "query": {
           "match_all": {}
        }
     }

其他回答

最简单的方法!

Endpoint :
http://localhost:9201/twitter/_delete_by_query

Payload :
{
  "query": { 
    "match": {
      "message": "some message"
    }
  }
}

在弹性搜索中,twitter在哪里是索引

裁判;https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html

您可以删除一个或多个索引,这实际上是从磁盘删除它们的文件。例如:

curl -XDELETE localhost:9200/$INDEXNAME

其中$INDEXNAME可以是索引名(例如users_v2), N个用逗号分隔的索引(例如users_v2,users_v3)。索引模式(例如users_*)或_all也可以,除非它在配置中通过action.destructive_requires_name: true被阻止。

删除单个文档是可能的,但这不会立即清除它们。删除只是一种软删除,在段合并过程中真正删除文档。在这个演讲中,你会发现很多关于分段和合并的细节。它是关于Solr的,但是合并来自Lucene,所以你在Elasticsearch中有相同的选项。

回到API,你可以通过ID删除单个文档(如果你使用路由索引,则提供路由值):

curl -XDELETE localhost:9200/users_v2/_doc/user1

或通过查询:

curl -XPOST -H 'Content-Type: application/json' localhost:9200/users_v2/_delete_by_query -d '{
  "query": {
    "match": {
      "description_field": "bad user"
    }
  }
}'

删除所有索引的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)

假设我需要删除索引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”:正确 }。

你也可以使用chrome扩展elasticsearch-head删除索引