Search code examples
javasearchindexingsolrsolrj

Delete an entire index with SolrJ


I'm using SolrJ to index articles on my site. Periodically, I'm going to want to clear the whole index and do a fresh re-index of all articles.

The ID of each entry is tied to the ID of the article (something to the effect of [blog ID]-[article ID]). I know that SolrJ has a deleteById() method, but if an article is removed from my site, I may lose access to its ID on the Java side, so I can't reliably iterate over all articles and call deleteById(). Is there any way to drop an entire index using SolrJ?


Solution

  • Use

    server.deleteByQuery( "*:*" );
    

    Then

    server.commit()
    

    You should first delete by query, do a full index, and then commit, so that the old index remains until the new one is committed.