英文:
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");
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论