9

Hi everyone I have 100 index into my elasticsearch and I want to delete them with one query. They all begin with myindex:

myindex-1
myindex-2
myindex-3
myindex-4
  .
  .
  .
myindex-100

when I try this query, it does not work:

curl -XDELETE http://localhost:9200/myindex*

I get:

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"}],"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"},"status":400}

Do you have any idea?

a.moussa
  • 2,977
  • 7
  • 34
  • 56

2 Answers2

12

You could use The following in kibana dev tool:

PUT /_cluster/settings
{
  "transient": {
  "action.destructive_requires_name":false

  }
}
Orsius
  • 830
  • 1
  • 11
  • 18
10

Elasticsearch documentation says:

The delete index API can also be applied to more than one index, by either using a comma separated list, or on all indices (be careful!) by using _all or *as index.

In order to disable allowing to delete indices via wildcards or _all, set action.destructive_requires_namesetting in the config to true. This setting can also be changed via the cluster update settings api.

So this could work if you have a predefined number of indices to delete:

curl -XDELETE http://localhost:9200/myindex-1,myindex-2,myindex-3,myindex-4

If you want to use wildcards you'll have to update the configuration as stated above

Community
  • 1
  • 1
whites11
  • 12,008
  • 3
  • 36
  • 53
  • Just be careful: Wildcards are allowed by default as stated in the quoted documentation (though the sentence is a bit confusing). – xeraa Sep 02 '17 at 18:40
  • used this technique after being meowed (sad face), after securing my server (happy face) – robasta Jul 28 '20 at 18:01