如何在Rails应用程序中使用带有ES 2.X版本的delete_ by_query插件从索引中删除所有数据? [英] How to delete all data from an index using delete_ by_query plugin with ES 2.X versions in rails app?

查看:155
本文介绍了如何在Rails应用程序中使用带有ES 2.X版本的delete_ by_query插件从索引中删除所有数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 elasticsearch 升级到 2.0版本 rails 4.2.7 应用,并尝试使用按查询删除插件。我怎样才能做到这一点?

i正在使用delete_by_query方法

I have upgraded my elasticsearch to 2.0 version in my rails 4.2.7 app and am trying to delete all index data using delete-by-query plugin. How can i achieve this?
i was using delete_by_query method like this

Elasticsearch::Model.client
                    .delete_by_query(index: index_klass.index_name,
                                     body: {query: {match_all: {}}})

但这在ES 2.X版本中已弃用。所以我该如何使用插件来做到这一点。提前致谢。

But this is deprecated in ES 2.X versions. so how can i use plugin to do this. thanks in advance.

推荐答案

我强烈建议删除整个索引并重新创建它,而不是删除索引中的所有数据

删除文档会将其标记为已删除,但实际上并没有从磁盘上实际删除它们。当发生Elasticsearch的自动合并过程时,这些实际上将被删除。但是,合并过程将考虑某些段文件仅用于删除,并且最肯定的是,您仍然会拥有没有文档的索引所使用的磁盘空间。有关细分合并的更多信息: https:// www。 elastic.co/guide/en/elasticsearch/guide/current/merge-process.html 以及有关在合并时删除这些文档的更多信息- https://www.elastic.co/blog/lucenes-handling-of-deleted-documents

Deleting the documents will mark them as deleted, but not actually physically deleting them from disk. When the automatic merging process of Elasticsearch happens then those will actually be deleted. But, the merging process will consider certain segment files for deletions only and most certainly you will still have disk space being used by an index which has no documents. More about segments' merging: https://www.elastic.co/guide/en/elasticsearch/guide/current/merge-process.html and more about the deletion of these documents at merge time - https://www.elastic.co/blog/lucenes-handling-of-deleted-documents

因此,只需删除索引并重新创建索引,您就会好得多。

So, you should much much better by simply deleting the index and recreating it.

这篇关于如何在Rails应用程序中使用带有ES 2.X版本的delete_ by_query插件从索引中删除所有数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆