API xóa Index trong Elasticsearch – Hướng dẫn xóa Index Elasticsearch

API xóa Index trong Elasticsearch – Hướng dẫn xóa Index Elasticsearch

(Xem thêm: Hướng dẫn Elasticsearch)

Trong các ví dụ API Elasticsearch, mình sẽ dùng postman để gửi request

API xóa Index trong Elasticsearch

Để tạo Index trong Elasticsearch ta dùng method DELETE với url /

DELETE /index_name

Ví dụ xóa index "user"

DELETE localhost:9200/user

API xóa Index trong Elasticsearch – Hướng dẫn xóa Index Elasticsearch

Trường hợp index cần xóa không tồn tại thì sẽ trả về lỗi “index_not_found_exception”

API xóa Index trong Elasticsearch – Hướng dẫn xóa Index Elasticsearch

Xóa nhiều index trong cùng 1 request

Để xóa nhiều index trong cùng 1 request, ta nối các index cần xóa bằng dấu phẩy

DELETE /index_name_1,index_name_2

Ví dụ: xóa 2 index là personplayer

DELETE localhost:9200/person,player

Xóa nhiều index trong cùng 1 request - elasticsearch

Xóa tất cả Index trong 1 request

Trường hợp muốn xóa tất cả Index, ta thay index_name thành _all

DELETE /_all

Ví dụ:

xóa tất cả index elasticsearch trong 1 request

Việc xóa tất cả các index khá nguy hiểm, để tắt chức năng xóa tất cả index với thẻ _all ta cài đặt tham số

action.destructive_requires_name = true trong file cấu hình elasticseach

 

Okay, Done!

References:

https://www.elastic.co/…/indices-delete-index.html

stackjava.com