Solrj无法连接

问题描述:

我通过运行包含的例子bin/solr -e cloud开始Solrcloud从Solr的云实例饲养员,并且在这种情况下,我成功地启动了三个节点Solr的云和创建gettingstarted集合:Solrj无法连接

http://localhost:8983/solr/admin/collections?action=CREATE&name=gettingstarted&numShards=3&replicationFactor=2&maxShardsPerNode=2&collection.configName=gettingstarted 

我认为它与在端口9983上运行的嵌入式动物园管理员,因为我看到这个输出,当我开始云:

... 
Starting up Solr on port 7574 using command: 
bin/solr start -cloud -p 7574 -s "example/cloud/node2/solr" -z localhost:9983 
Waiting up to 30 seconds to see Solr running on port 7574 [/] 
... 

然而,当我试图连接使用SolrJ的SolrCloud时,它失败,出现错误信息:

Exception in thread "main" org.apache.solr.common.SolrException: Cannot connect to cluster at localhost:9983/solr: cluster not found/not ready 

enter image description here

谁能帮我明白这到底是怎么回事呢?

+0

对于任何人想知道,Zookeeper连接字符串应该包含zookeeper集群中的所有zookeeper服务器,用逗号分隔,有些zookeeper配置使用chroot或应用程序根目录,这是''/ solr''出现在查询字符串的末尾。当你在Zookeeper中的''/ solr''上有一个chroot时,这将是必需的。对于大多数配置,这可以省略。 –

+0

@BenDeMott也许这应该是一个答案? –

代码失败,因为您试图将CloudSolrServer指向一个不存在的znode。 您的zkhost未配置/solr chroot。配置似乎存储在根节点。

因此改线

String zkHostString = "localhost:9983/solr"; 

String zkHostString = "localhost:9983"; 

和你的代码应该工作。

这取决于你的zkHost。如果你的zkHost包含/ solr,那么它应该是localhost:2181/solr或localhost:9983/solr;否则,localhost:yourport