How to delete all data from an index without deleting the index?

Hello,

I am looking for a simple and efficient way to delete all data from an index without deleting the index. This is known as a truncate in SQL parlance.

The rationale is that I want to clear the data while leaving typing and permissions intact. Both typing and permissions are complicated and it's not something I want to do repeatedly anyway.

This posting asks the same question and goes like this: "You can use delete by query, but it's seriously inefficient." "What if I don't care that it's inefficient?" "Why not just delete it and repopulate?"

So I open a feature request which gets summarily closed with "use delete by query". This is a fundamental feature which deserves a good answer.

Create an index template with settings and mappings. You Dan the delete the index and be sure it is recreated with correct mappings when it is recreated. This s the closest to a truncate you will get.

Welcome to our community! :smiley:

As you've seen, having it both of these is not possible in Elasticsearch, it's just the way that it works.

Your best option is to follow Christian's suggestions.