Delete all data from index without deleting index?

Hello,

As per the topic title, is it possible to delete all data from an index without deleting the index? I don't want to have to recreate the fields and dashboards/visualizations (I know I can export those but still).

2 Likes

You can using a delete by query, but it's seriously inefficient.

6 Likes

Would you mind sharing the query?

As long as it deletes everything but leaves the index & visualizations alone I don't mind its inefficient. This is just test data and its not that much data so I don't mind having to wait a bit longer.

Why not just delete the specific index and repopulate?
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-delete-by-query.html

2 Likes

Yes. Just to make sure that everything is clear. When you run a

DELETE my_index

You just remove your index data but you don't touch .kibana index which contains all the kibana stuff.

6 Likes

I ended up doing that but it looks like you can't use wildcards (e.g twitter-*) so I had to delete 40 indexes by hand.

@dadoonet Thanks, I'll remember that one for next time.

Sure you can.

curl -XDELETE 0:9200/twitter*.

3 Likes

I couldn't get it working with the example on the user guide.

Anyway I tried @dadoonet 's recommendation and that worked like a charm. Requires the least amount of typing too.

Try escaping the wildcard, like this:

curl -XDELETE 0:9200/twitter-\*

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.