Loading...

Delete Elasticsearch index-name with special characters

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

If you working with logstash and set the index name dynamically from variables, you might run into situations where the variable is not substituted due to errors. You can get rid of this bad indices by deleting them with the REST API of elasticsearch. The challenge lies in escaping the special characters.

An example what might happen:

curl -s http://localhost:9200/_cat/indices
green open  .marvel-es-2016.03.16        1 1  750253 5159 717.1mb 358.5mb
green open  fo-%{environment}-2016.03.19 5 1     186    0   346kb   173kb
green open  .marvel-es-2016.03.17        1 1  772223 5592 726.5mb   367mb
green open  .marvel-es-2016.03.18        1 1  753400 3932   777mb 388.4mb

To delete the second index we have to escape

  • % → %25
  • { → %7B
  • } → %7D
curl -XDELETE http://localhost:9200/fo-%25%7Benvironment%7D-2016.03.19
Please remember the terms for blog comments.