简体   繁体   English

在Elasticsearch中批量删除特定类型的文档

[英]Bulk delete documents of a specific type in elasticsearch

I have an index called "animals" in elasticsearch. 我在elasticsearch中有一个称为“动物”的索引。 That contains several documents of type "dogs". 包含几个“ dogs”类型的文档。 I want to delete all "dogs" documents in "animals" index. 我想删除“动物”索引中的所有“狗”文档。 I am using python elasticsearch package. 我正在使用python elasticsearch包。 My python code is as follows: 我的python代码如下:

connection = Elasticsearch([{"host": "myhost", "port": "myport" } ])
body = {} # What should I put in the body???
connection.bulk(body, index="animals", doc_type="dogs", ignore=[400, 404])

Here I don't know what do I need to put in the body . 在这里,我不知道我需要什么,放于body Can anyone help me out? 谁能帮我吗?

Bulk method is defined at https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/client/ init .py#L1002 批量方法在https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/client/ init .py#L1002中定义

There is no api in elasticsearch-py to delete all documents of a type. elasticsearch-py没有api来删除所有类型的文档。 This is because Elasticsearch 2.x onwards there is no api to delete a type . 这是因为从Elasticsearch 2.x开始,没有用于删除type api。 From the documentation 文档中

In 1.x it was possible to delete a type mapping, along with all of the documents of that type, using the delete mapping API. 在1.x中,可以使用Delete Mapping API删除类型映射以及该类型的所有文档。 This is no longer supported, because remnants of the fields in the type could remain in the index, causing corruption later on. 不再支持此操作,因为类型中字段的剩余部分可能保留在索引中,从而在以后导致损坏。

Instead, if you need to delete a type mapping, you should reindex to a new index which does not contain the mapping. 相反,如果需要删除类型映射,则应将索引重新索引为不包含该映射的新索引。 If you just need to delete the documents that belong to that type, then use the delete-by-query plugin instead. 如果您只需要删除属于该类型的文档,则可以使用按查询删除插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM