Delete Elasticsearch indices using wildcard expression.
List indices.
$ curl -u elastic:elastic "https://192.168.8.153:9200/_cat/indices/nginx*?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open nginx-logs-2023-07-25 hbcUxgMGTrS5gZ08TV6RaA 1 1 0 0 450b 225b green open nginx-logs-2023-07-24 YF8XoGKHTUa2uT_dIN2qMg 1 1 0 0 450b 225b green open nginx-logs-2023-07-23 Il9uZxM-RMm5g7rpynG8bg 1 1 0 0 450b 225b green open nginx-logs-2023-07-22 MpEyNWVQSL-NrtCB8ACIpQ 1 1 0 0 450b 225b
Try to delete multiple indices using wildcard expression.
$ curl -X DELETE -u elastic:elastic "https://192.168.8.153:9200/nginx*?pretty"
{ "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 }
Allow using wildcards (including _all
keyword) to delete multiple indices.
$ curl -X PUT -u elastic:elastic "https://192.168.8.153:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'{"persistent": {"action.destructive_requires_name":false}}' { "acknowledged" : true, "persistent" : { "action" : { "destructive_requires_name" : "false" } }, "transient" : { } }
{ "acknowledged" : true, "persistent" : { "cluster" : { "routing" : { "allocation" : { "enable" : "primaries" } } } }, "transient" : { } }
Verify persistent settings.
$ curl -s -u elastic:elastic "https://192.168.8.153:9200/_cluster/settings?include_defaults=true"| jq .persistent
{ "action": { "destructive_requires_name": "false" } }
Delete multiple indices using wildcard expression.
$ curl -X DELETE -u elastic:elastic "https://192.168.8.153:9200/nginx*?pretty"
{ "acknowledged" : true }
List indices.
$ curl -s -u elastic:elastic "https://192.168.8.153:9200/_cat/indices/nginx*?format=json" | jq .
[]