Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Solrj DeleteByQuery不工作_Java_Solr_Solrj_Solr4_Solr4j - Fatal编程技术网

Java Solrj DeleteByQuery不工作

Java Solrj DeleteByQuery不工作,java,solr,solrj,solr4,solr4j,Java,Solr,Solrj,Solr4,Solr4j,我已经花了3个多小时来解决这个问题,但不幸的是我无法解决它。有人能帮我吗 下面是我在使用solrj运行deletebyQuery时遇到的异常,而添加到solr正在工作注意:deletebyQuery不起作用,但add起作用 org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://localhost:8090/solr/abc at org

我已经花了3个多小时来解决这个问题,但不幸的是我无法解决它。有人能帮我吗

下面是我在使用solrj运行deletebyQuery时遇到的异常,而添加到solr正在工作注意:deletebyQuery不起作用,但add起作用

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 
这是我的SolrServerHolder代码

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;
    }

}
下面是我的代码,它将尝试通过查询和引发异常来删除数据:

SolrClient server =SolrServerHolder.getConcurrentSolrServer();
server.deleteByQuery("id:65657575", 12000);
server.commit();
如果我试图将文档添加到solr中,它工作得非常好

SolrInputDocument docs = getDocs();
SolrClient server =SolrServerHolder.getConcurrentSolrServer();
server.add(abc);
server.commit();
我曾经提出过类似的问题和解决方案,但对我没有帮助


没有答案,但我在尝试使用deleteByQuery时遇到了多个问题(bug?)。最终使用自定义http调用来实现这一点。但是,对于您的情况,您是否尝试使用deleteById方法?或者你的查询只是一个例子?@talyyweb是的,我也尝试过deletebyid,它同样的问题:(自定义http调用,ti对你有用吗?你能帮我一下吗?首先,尝试使用curl(或使用浏览器)执行此操作)并向
http://yourlogin:yourpassword@localhost:8090/solr/abc/update?stream.body=id:6565657575&commit=true
如果这对您有效,解决方法基本上是使用http客户端(如Apache HttpClient)编写脚本。但首先检查它是否与curl一起工作。@talyyweb是的,这很有帮助。谢谢。