2

I try to delete all templates in my local instance .but it fail and I got this message .How do I delete all templates ? I don't understand this error.

My query :

DELETE /_template

error :

{
 "error": "Incorrect HTTP method for uri [/_template] and method [DELETE], allowed: [GET]",
"status": 405}

2 Answers2

4

this seemed to work for me on linux to delete all templates:

curl -X DELETE "http://localhost:9200/_template/*"

this is with elasticsearch 2.4

Dharman
  • 30,962
  • 25
  • 85
  • 135
AC.
  • 1,005
  • 2
  • 12
  • 20
2

There is no such possibility to remove all the templates at once.

You can first get all the existing templates list with:

GET /_template

and next remove one by one using their names:

DELETE /_template/NAME_OF_THE_FIRST_TEMPLATE
DELETE /_template/NAME_OF_THE_SECOND_TEMPLATE
DELETE /_template/NAME_OF_THE_THIRD_TEMPLATE
...

Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

Piotr Pradzynski
  • 4,190
  • 5
  • 23
  • 43
  • Above but with curl, jq and xargs `curl http://localhost:9200/_template | jq -r 'keys[]' | xargs -I {} curl -XDELETE "http://localhost:9200/_template/{}"` – avalanchy Aug 18 '23 at 12:34