I was using this curl command line to clean my indices:
curl -XDELETE http://example.com/my_index-*
But, now, I want to delete my_index-.*[.][0-3][0-9]:
my_index-YYYY.MM.dd
my_index-YYYY.MM.dd-*
The relevant Elasticsearch documentation I have found:
Delete index API does say nothing on regex.
Multiple indices says:
It also support wildcards, for example:
test*or*testorte*tor*test*, and the ability to "add" (+) and "remove" (-), for example:+test*,-test3.
Date math support in index names says:
Almost all APIs that have an
indexparameter, support date math in theindexparameter value.
[...]date_formatis the optional format in which the computed date should be rendered. Defaults toYYYY.MM.dd.
My Questions:
DELETE request method to Elasticsearch HTTP server to delete indices only formatted my_index-YYYY.MM.dd?my_index-* but keeping my_index-*-*?For example, regex can sometimes be provided within the POST data:
curl -XPOST http://example.com/my_index-2017.07.14/_search?pretty' -H 'Content-Type: application/json' -d'
{
"suggest": {
"song-suggest" : {
"regex" : "n[ever|i]r",
"completion" : {
"field" : "suggest"
}
}
}
}'
To delete all indices, use _all or * . To disallow the deletion of indices with _all or wildcard expressions, set the action. destructive_requires_name cluster setting to true .
You cannot delete the current write index of a data stream. To delete the index, you must roll over the data stream so a new write index is created.
Delete all indices my_index-* except indices my_index-*-*
curl -X DELETE http://es.example.com/my_index-*,-my_index-*-*
Elasticsearch 5.x does not accept regex or filename patterns ?[a-z] to select multiple indices.
However, the multiple indices documentation allows + and - to include and exclude indices.
Script to prevent accidental deletion of indices my_index-*-*:
#!/bin/bash -xe
pattern="${1:-*}"
curl -X DELETE https://es.example.com/my_index-"$pattern",-my_index-*-*?pretty
index can contain a comma separated list of index patterns, for example my_index_1,my_index_2,my_index_3.my_index*.+ and - as index prefix, for example my_index_*,-my_index_2017*,+my_index_2017-01*,-my_index_2017-01-31.+ on first indexThis DELETE request deletes all indices my_index_* before my_index_2017-01-31
index_list='my_index_*,-my_index_2017*,+my_index_2017-01*,-my_index_2017-01-31'
curl -X DELETE http://es.example.com/"$index_list"
my_index_*
my_index_2017*
my_index_2017-01*
my_index_2017-01-31
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With