Delete all indices with specific pre-fix using JAVA APIs

Hi all,
Does anyone know how to perform
curl -XDELETE "http://localhost:9200/test_*;"
via JAVA APIs?

I found the way to delete a particular index, but I have multiple indices with a particular prefix and a special event requires me to delete all the indexes with that particular prefix, since the data will be invalid for those indexes.

Any help appreciated. :slight_smile:

What did you try ?

If it’s one time only operation why not doing that with the rest api?

Hi,
I tried the following thing,

client = elasticSearchConnection.getClient();
client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();

Here the problem is that I'll have to fetch all the indices, and check the index name for particular index prefix and if it qualifies to be deleted, then only delete it.
But as i was thinking, If it is possible to delete using wildcard entries, why not use it.

Also, I'm not much inclined to use the rest as I already have the client object and adding REST will add another flow of code and add maintenance overhead.
But REST would be the last fall-through if nothing works.

Why not doing:

client.admin().indices().delete(new DeleteIndexRequest("test_*")).actionGet();

Is this not working?

I was just about to try that.
I'll share the outcome in a bit.
Thanks :slight_smile:

Hi @dadoonet
That works.
It was stupid of me to not try that before posting here.
Thanks :slight_smile:

No worries.

In case of doubt, just try to look at the REST class in elasticsearch code.
You'll see basically what is done behind the scene. Like here:

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