sebpiq
sebpiq

Reputation: 7802

Deleting all documents of a type and keeping the type

I am trying to delete all indices of one type. Tried to execute this :

curl -XDELETE 'http://localhost:9200/myindex/mytype/_query' -d '{"query": {"match_all": {}}}'

But this doesn't delete anything. The following query shows that my index is still there.

curl -XGET 'http://localhost:9200/myindex/mytype/_search' | json -i

What am I doing wrong?

Upvotes: 0

Views: 584

Answers (2)

cfrick
cfrick

Reputation: 37033

to delete the whole type you call DELETE on it

curl -XDELETE localhost:9200/myindex/mytype

this deletes the type mytype in the index myindex.

be aware, that this deletes also any mappings etc with the type. but i would consider this a more resource-friendly way (but can not proove it)

Upvotes: 2

sebpiq
sebpiq

Reputation: 7802

Nevermind. I found this answer myself from this question Delete records from Elasticsearch by query

The body to send with the request is just the query. So basically the right request is :

curl -XDELETE 'http://localhost:9200/myindex/mytype/_query' -d '{"match_all": {}}'

Upvotes: 1

Related Questions