How to delete all data from an index using delete_ by_query plugin with ES 2.X versions in rails app?

梦想与她 提交于 2019-12-24 08:25:45

问题


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: {}}})

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


回答1:


Instead of deleting all the data in an index, I strongly suggest deleting the entire index and re-creating it.

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.




回答2:


You have two solutions:

  1. upgrade to ES 5.0 which has brought the delete-by-query API back into the core.
  2. stay on 2.x and install the delete-by-query plugin

Thereafter, you code will work again.



来源:https://stackoverflow.com/questions/40395463/how-to-delete-all-data-from-an-index-using-delete-by-query-plugin-with-es-2-x-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!