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

DELETE FROM [Index]

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

   http://localhost:9200/[indexName]

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


当前回答

最简单的方法!

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或使用开源爱好者为Elasticsearch创建的许多工具中的任何一个进行可视化删除。

使用旋度

curl -XDELETE localhost:9200/index/type/documentID

e.g.

curl -XDELETE localhost:9200/shop/product/1

然后,您将收到关于此操作是否成功的回复。你可以删除整个索引,也可以删除带有索引的类型,你也可以删除一个类型,就像这样,去掉文档ID

curl -XDELETE localhost:9200/shop/product

如果您希望删除索引-

curl -XDELETE localhost:9200/shop

如果您希望删除多个遵循特定命名约定的索引(注意*,通配符),则-

curl -XDELETE localhost:9200/.mar* 

在视觉上

上面提到了各种各样的工具,我不会在这里列出它们,但我会链接到一个可以让你直接开始的工具,位于这里。这个工具被称为KOPF,要连接到您的主机,请单击左上角的标志,并输入您的集群的URL。

一旦连接,您将能够管理您的整个集群,删除,优化和调优您的集群。

在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')

你可以试试这个卷发:

curl --location --request DELETE 'http://<username>:<password>@<url>:9200/<index name>/<doc type>/<document id>

或者如果你不想在URL上设置用户名和密码,那么也可以尝试这个curl:

curl --location --request DELETE 'http://<url>:9200/<index name>/<doc type>/<document id>' --header 'Authorization: Basic <Base64 encoded username:password>'

执行后,响应体将包含一个结果字段。如果该字段的值被删除,则意味着文档删除成功。

在这个curl中,我假设您已经将您的elastic配置为使用http。如果您正在使用https,只需将协议更改为https。

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

这里有很多很好的答案,但我也想补充一点:

如果你在AWS ElasticSearch服务上运行,你不能删除/删除索引。不是删除索引,而是必须重新索引它们。