Wednesday, June 13, 2012

Solr - Clean up Index



Sometimes you want to delete all the records from the Solr index without deleting the index directory.
This can be done by executing an http url :-
http://host:port/solr/core/update?stream.body=<delete><query>*:*</query></delete>&commit=true



Or by posting data xml data :-
<delete><query>*:*</query></delete>

Cleaning data using Solrj :-

SolrServer server = null;
try {
    server = new CommonsHttpSolrServer(masterIndexUrl);
    server.deleteByQuery("*:*");
    server.commit(true, true);
    server.optimize(true, true);            
} catch (Exception e) {
    try {
        server.rollback();                
    } catch (Exception e1) {
        
    }
}

1 comment:

  1. It is amazing that you have finally reached this point. i think that you had to overcome many obstacles that require the good physical availability.
    KissAnime

    ReplyDelete