Search code examples
javasolrsolrj

solr cannot delete anything


I'm trying to delete documents on my solr server, but it doesn't work and I get no error.

I tried deleting via browser, curl and solrj and nothing works.

(browser and curl as explained here: Solr delete not working for some reason)
My solrj code is:

server.deleteByQuery("*:*");
server.deleteById("*");
server.deleteById("guid:*");
server.commit(true, true);

UpdateRequest update = new UpdateRequest();
update.deleteByQuery("*:*");
update.setCommitWithin(0);
server.request(update);
server.commit(true, true);

SolrQuery query = new SolrQuery("*:*");//Search for everything/anything
query.setRows(10);
query.setRequestHandler("/query");
QueryResponse qr = server.query(query); 
SolrDocumentList result = qr.getResults();
for (SolrDocument doc : result) {
    Object id = doc.get("link");
    String names = (String) doc.get("description");
System.out.println(id + " " + names);
}

I always get results after executing this, or via the web interface, nothing changes (adding documents works by the way).

Anyone has and idea what I can try or what could be the reason for this?

UPDATE:

So I tried to setup everything from scratch again and I localized the error source: solr doesn't delete documents with my Schema.xml file, I still don't know why though: schema.xml on pastebin


Solution

  • I found the reason: bug in solr 4.0.0 alpha

    the field:

    <field name="_version_" type="long" indexed="true" stored="true"/>
    

    is required for deleting in your schema.xml file if you enable the update log in your solrconfig.xml, if you don't have this field your delete update queries are ignored.

    <updateHandler class="solr.DirectUpdateHandler2">
      <updateLog>
        <str name="dir">${solr.data.dir:}</str>
      </updateLog>
    </updateHandler>
    

    This happens to everyone who uses the configurations from the examples in solr and just changes the Schema.xml file.