solr cannot delete anything

2019-05-26 05:03发布

问题:

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

回答1:

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.



回答2:

I have a working code like this:

SolrServer solrServer;
String url = "http://localhost:8080/solr";
solrServer = new HttpSolrServer(url);
solrServer.deleteByQuery("*:*");
solrServer.commit();

My Solr version is 3.6.1.



回答3:

//Delete particular column using Solr

SolrServer solrServer;

solrServer = new HttpSolrServer(url);

solrServer.deleteByQuery("columnName:value");

solrServer.commit();


标签: java solr solrj