简体   繁体   中英

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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