Clearing a Solr search index
alphadevx.com Date Added: 2012-04-26 Last Updated: 2012-05-14 Revision: 7
When developing a search project using Apache Solr, you often need to clear out the search index and start again. A typical example of this is when you make a schema change. Luckily, there is an easy way to do this via the Solr REST API.
According to the official Solr FAQ, you can clear out a Solr index by issuing the following query:
To run this query, you can issue it via the REST API using curl:
Note that you will also need to tell Solr to commit this change:
...and it is also a good idea to tell Solr to optimize it's index at this point:
To confirm that your index is now empty, load up the Solr admin web interface in your browser, and click on the statistics link. You should now see that the number of documents listed in your index is now zero.
Note that the final optimize command is passed to Solr to tell it to physically remove the deleted documents, which will not only free up disc space, but will also increase search performance. Following the above procedure of delete/commit/optimize will ensure that you start off with a clean slate each time.
Article URL: http://www.alphadevx.com/a/365-Clearing-a-Solr-search-index
Title: Clearing a Solr search index
Author: John Collins
© 2001-2013, all rights reserved.