2017-10-17 75 views
0

您好,我在我的solr客戶端中有以下代碼。Solr版本6.6.1和http核心和客戶端版本

試圖連接到服務器。

System.out.println("Initializing server"); 
SystemDefaultHttpClient cl = new SystemDefaultHttpClient(); 
client = new HttpSolrClient("http://localhost:8983/solr/#/prosp_poc_collection",cl); 
System.out.println("Completed initializing the server"); 
client.deleteByQuery("*:*"); 

當它試圖刪除所有數據時,我得到下面的錯誤。
solr版本6.6.1 http-core 4.4.8和http客戶端4.5.3。

org/apache/solr/client/solrj/impl/HttpClientUtil.createClient(Lorg/apache/solr/common/params/SolrParams;)Lorg/apache/http/impl/client/CloseableHttpClient; @57: areturn 
    Reason: 
    Type 'org/apache/http/impl/client/SystemDefaultHttpClient' (current frame, stack[0]) is not assignable to 'org/apache/http/impl/client/CloseableHttpClient' (from method signature) 
    Current Frame: 
    bci: @57 
    flags: { } 
    locals: { 'org/apache/solr/common/params/SolrParams', 'org/apache/solr/common/params/ModifiableSolrParams', 'org/apache/http/impl/client/SystemDefaultHttpClient' } 
    stack: { 'org/apache/http/impl/client/SystemDefaultHttpClient' } 
    Bytecode: 
    0x0000000: bb00 0959 2ab7 000a 4cb2 000b b900 0c01 
    0x0000010: 0099 001e b200 0bbb 000d 59b7 000e 120f 
    0x0000020: b600 102b b600 11b6 0012 b900 1302 00b8 
    0x0000030: 0014 4d2c 2bb8 0015 2cb0    
    Stackmap Table: 
    append_frame(@47,Object[#172]) 

    at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:514) 
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279) 
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268) 
    at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:160) 
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:895) 
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:858) 
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:873) 

回答

0

我假設prosp_poc_collection是您正在使用的集合的名稱。

首先嚐試指定沒有錨#的Url,這是正確的方法。

再次,在你使用已棄用HttpSolrClient constructor,嘗試了這種方式:

String urlString = "http://localhost:8983/solr/prosp_poc_collection"; 
SolrClient solrClient = new HttpSolrClient(urlString); 

https://lucene.apache.org/solr/6_6_1/solr-solrj/org/apache/solr/client/solrj/impl/HttpSolrClient.html

在另一方面,另一種方法是使用HttpSolrClient.Builder

solrClient = new HttpSolrClient.Builder("http://localhost:8983/solr/prosp_poc_collection") 
          .build();