Solr 版本 6.6.1 和 http 核心和客户端版本

Solr version 6.6.1 and http core and client versions

您好,我的 solr 客户端中有以下代码。

正在尝试连接到服务器。

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 client 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)

我假设 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 class

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