在Apache Solr中如何检索已删除的文档

huangapple go评论69阅读模式
英文:

In Apache Solr How to retrieve deleted documents

问题

每当我使用Solr索引文档时,我的核心已删除文档的计数也在增加。我想查看被删除的文档。

英文:

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.

答案1

得分: 0

你可以附加一个监听器并在条目被删除之前记录它们。你也可以将它们写入一个自定义文件中,该文件仅包含已删除条目的详细信息。

在删除条目时,你可以使用以下代码示例来实现自己的逻辑:

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 {
      // 准备 Solr 客户端
      String urlString = "http://localhost:8983/solr/my_core";
      SolrClient solr = new HttpSolrClient.Builder(urlString).build();

      // 准备 Solr 文档
      SolrInputDocument doc = new SolrInputDocument();

      // 从 Solr 中删除文档
      solr.deleteByQuery("*");

      // 保存文档
      solr.commit();
      System.out.println("文档已删除");
   }
}
英文:

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"); 
   } 
}

huangapple
  • 本文由 发表于 2020年8月10日 19:02:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63338914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定