Skip to content

Instantly share code, notes, and snippets.

@dnault
Created January 25, 2018 20:19
Show Gist options
  • Save dnault/2b6d4c8b675868e00ad5f8b159348e3b to your computer and use it in GitHub Desktop.
Save dnault/2b6d4c8b675868e00ad5f8b159348e3b to your computer and use it in GitHub Desktop.
Delete all documents from an Elasticsearch index
#!/bin/sh
INDEX=$1
# optionally limit the deletion to a specific type
TYPE=$2
BASE_URL=http://localhost:9200
if [ "$#" -eq 1 ]; then
URI_PATH=$1
elif [ "$#" -eq 2 ]; then
URI_PATH=$1/$2
else
echo "USAGE: es-clear.sh <index> [type]"
exit 1
fi
curl -XPOST http://localhost:9200/$URI_PATH/_delete_by_query -d '{
"query": {
"match_all": {}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment