Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting index from Solr using solrj as a client

Tags:

solr4

solrj

solr5

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!

like image 250
azhar_salati Avatar asked Apr 17 '10 05:04

azhar_salati


People also ask

How do I delete data from Solr?

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.

What is SolrJ in Solr?

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.

How does Solr integrate with Java application?

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.


2 Answers

When you call deleteById, just use the id, without query syntax:

server.deleteById("20");
server.commit();
like image 124
itsadok Avatar answered Oct 05 '22 23:10

itsadok


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 );
like image 24
joshwa Avatar answered Oct 05 '22 22:10

joshwa