Solrj DeleteByQuery is not working

2019-09-01 10:17发布

问题:

I have spent more than 3 hours of time to fix this issue, but unfortunately i am not able to fix it. Can anyone help me on this ?

Here is the exception i am getting while running deletebyQuery using solrj while adding to solr is working. Note : deletebyQuery is not working but add is working.

org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://localhost:8090/solr/abc
    at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:589)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:241)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:230)
    at org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.request(ConcurrentUpdateSolrClient.java:351)
    at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:150)
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:896)
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:914)
    at net.merger.prune.Merger.run(Merger.java:19)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:886)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:480)
    ... 14 more
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:663)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
    ... 18 more 

and here is my SolrServerHolder code.

public class SolrServerHolder {
    private static SolrClient concurrentSolrServer = null;
    private static HttpSolrClient solrServer = null;
    @SuppressWarnings("deprecation")
    private static HttpSolrServer httpServer = null;
    private static DefaultHttpClient client = null;

    private static synchronized void initHttpClient() {
        try {
            PoolingClientConnectionManager connManager = new PoolingClientConnectionManager();
            connManager.setDefaultMaxPerRoute(20); // Allow upto 20 connections for solr server
            connManager.setMaxTotal(1000);
            client = new DefaultHttpClient(connManager);
        } catch (Error e) {
            e.getMessage();
        }
    }

    private static synchronized void initConcurrentSolrServer() throws Exception {      
        if(client == null)
            initHttpClient();       

        UsernamePasswordCredentials defaultcreds = new UsernamePasswordCredentials("XXXX", "YYYY");
        client.getCredentialsProvider().setCredentials(
                new AuthScope("localhost", 
                        "8090", AuthScope.ANY_REALM),defaultcreds);

        concurrentSolrServer = new ConcurrentUpdateSolrClient("http://localhost:8090/solr/abc", client, 5000, 2);

    }

public static  SolrClient getConcurrentSolrServer() throws Exception {
        if(concurrentSolrServer == null)
            initConcurrentSolrServer();
        return concurrentSolrServer;
    }

}

and Here is my code which will trying to delete the data by query and throwing exception :

SolrClient server =SolrServerHolder.getConcurrentSolrServer();
server.deleteByQuery("id:65657575", 12000);
server.commit();

if i am trying to add docs to solr it is working perfectly Fine

SolrInputDocument docs = getDocs();
SolrClient server =SolrServerHolder.getConcurrentSolrServer();
server.add(abc);
server.commit();

I have refereed similar issues and solutions but it didn't help me.

Solrj Authentication Fails On Write Operation