I am using solrj as client for indexing documents on the solr server.
I am having problem while deleting the indexes by 'id' from the solr server. I am using following code to delete the indexes:
server.deleteById("id:20");
server.commit(true,true);
After this when i again search for the documents, the search result contains the above document also. Dont know what is going wrong with this code. Please help me out with issue.
Thanks!
Deleting the Document To delete documents from the index of Apache Solr, we need to specify the ID's of the documents to be deleted between the <delete></delete> tags. Here, this XML code is used to delete the documents with ID's 003 and 005. Save this code in a file with the name delete. xml.
SolrJ is an API that makes it easy for applications written in Java (or any language based on the JVM) to talk to Solr. SolrJ hides a lot of the details of connecting to Solr and allows your application to interact with Solr with simple high-level methods. SolrJ supports most Solr APIs, and is highly configurable.
Apache SolrJ Java API Let's initiate the SolrJ client by connecting to our Solr server: String urlString = "http://localhost:8983/solr/bigboxstore"; HttpSolrClient solr = new HttpSolrClient. Builder(urlString). build(); solr.
When you call deleteById, just use the id, without query syntax:
server.deleteById("20");
server.commit();
After you delete the document, commit the server and add the following lines. After the server commit line.
UpdateRequest req = new UpdateRequest();
req.setAction( UpdateRequest.ACTION.COMMIT, false, false );
req.add( docs );
UpdateResponse rsp = req.process( server );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With