Skip to content

Instantly share code, notes, and snippets.

@leedavis81
Created October 11, 2012 16:57
Show Gist options
  • Save leedavis81/3873871 to your computer and use it in GitHub Desktop.
Save leedavis81/3873871 to your computer and use it in GitHub Desktop.
Delete a solr core
#!/bin/bash
clear
echo "*************************************************************************"
echo "*************************************************************************"
echo
echo " You are about to *permanently* delete a core!"
echo " There is no going back"
echo
echo "*************************************************************************"
echo "*************************************************************************"
echo
echo -n "Type 'delete core' to continue or control-c to bail: "
read answer
if [ "$answer" != "delete core" ]; then
exit
fi
# removes a Solr core
if [ "$1" = "" ]; then
echo -n "Name of core to remove: "
read name
else
name=$1
fi
if [ ! -d /var/lib/solr/data/$name ] || [ $name = "" ]; then
echo "Core doesn't exist"
exit
fi
curl "http://127.0.0.1:8080/solr/admin/cores?action=UNLOAD&core=$name"
sleep 5
rm -rf /var/lib/solr/data/$name
rm -rf /etc/solr/conf/$name
@michaelgantman
Copy link

Actually according to this link https://wiki.apache.org/solr/CoreAdmin#UNLOAD you don't need to delete the folders manaually. Since Solr4.0 there are two more optional parameters are "deleteDataDir" and "deleteInstanceDir" on core unload.

deleteDataDir removes "data" and all sub-directories
deleteInstanceDir removes everything related to the core, the index directory, the configuration files, etc. This command would remove the directory core0 and all sub-directories.

So a curl command curl "http://127.0.0.1:8080/solr/admin/cores?action=UNLOAD&core=$name&deleteInstanceDir=true" will take care of the folder deleting automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment