Skip to content
Advertisement

In Apache Solr How to retrieve deleted documents

Whenever I am indexing Documents using solr ,my core deleted documents count also getting increased .I want to see the documents which are getting deleted.

Advertisement

Answer

You can attach a Listener and log entries before they will be deleted. You can also write them inside a custom file which contains only deleted entries details.

You can implement your own logic too with that code example when you delete entries : https://www.tutorialspoint.com/apache_solr/apache_solr_deleting_documents.htm

import java.io.IOException;  

import org.apache.Solr.client.Solrj.SolrClient; 
import org.apache.Solr.client.Solrj.SolrServerException; 
import org.apache.Solr.client.Solrj.impl.HttpSolrClient; 
import org.apache.Solr.common.SolrInputDocument;  

public class DeletingAllDocuments { 
   public static void main(String args[]) throws SolrServerException, IOException {
      //Preparing the Solr client 
      String urlString = "http://localhost:8983/Solr/my_core"; 
      SolrClient Solr = new HttpSolrClient.Builder(urlString).build();   
      
      //Preparing the Solr document 
      SolrInputDocument doc = new SolrInputDocument();   
          
      //Deleting the documents from Solr 
      Solr.deleteByQuery("*");        
         
      //Saving the document 
      Solr.commit(); 
      System.out.println("Documents deleted"); 
   } 
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement