Deleting index from Solr using solrj as a client
Asked Answered
T

4

9

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!

Trochilus answered 17/4, 2010 at 5:46 Comment(0)
B
17

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

server.deleteById("20");
server.commit();
Barrios answered 2/5, 2010 at 14:33 Comment(1)
will this work even if the document ids are integers?Cabinda
C
1

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 );
Canny answered 28/1, 2011 at 9:56 Comment(0)
M
0

Use the method deleteByQuery() to delete the documents matching the query:

server.deleteByQuery("id:20");
server.commit();
Meticulous answered 18/8, 2016 at 8:39 Comment(0)
H
-1

So the deleteById will work only if you are forming your key using only one attribute. So, I had case where the id was a combination of multiple attributes like employeeId+deptId. But, my table had employeeId & deptId as separate columns as well with indexes created on it. So when I wanted to delete a record I had only the employeeId and not deptId. I used the curl command to delete where you can specify the column and its value and it will delete the entire record.

E.g. curl http://localhost:8983/solr/update --data ':' -H 'Content-type:text/xml; charset=utf-8'

Holder answered 23/3, 2015 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.