How to erase ElasticSearch index?

后端 未结 4 1829
轻奢々
轻奢々 2021-02-01 16:57

My unit/integration tests includes tests for search functionality.

My idea is to have empty search index before each test. So, I\'m trying to remove al

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 17:02

    First of all you don't have to clear all data by issuing a delete on each doc id. You can just delete all data with delete by query matching all documents http://www.elasticsearch.org/guide/reference/api/delete-by-query.html Having that said I don't recommend that either, because it's not recommended to do this often on large doc collections (see docs).

    What you really want to do is delete the whole index (it's fast) http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-index.html , recreate it, put in data and this is important refresh the index to "commit" the changes and make them visible. http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh.html

    I do this in my tests and never had a problem.

提交回复
热议问题