B.M*_*.W. 7 solr solrj apache-zookeeper
我通过运行包含的示例启动了Solrcloud bin/solr -e cloud,在这种情况下,我设法启动了三个节点Solr云并创建了一个gettingstarted集合:
http://localhost:8983/solr/admin/collections?action=CREATE&name=gettingstarted&numShards=3&replicationFactor=2&maxShardsPerNode=2&collection.configName=gettingstarted
Run Code Online (Sandbox Code Playgroud)
我认为它带有一个在端口9983上运行的嵌入式zookeeper,因为我在启动云时看到了这个输出:
...
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 [/]
...
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用SolrJ连接到SolrCloud时,它失败并显示错误消息:
Exception in thread "main" org.apache.solr.common.SolrException: Cannot connect to cluster at localhost:9983/solr: cluster not found/not ready
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我理解这里发生了什么?
代码失败是因为您尝试将其指向CloudSolrServer不存在的znode.您的zkhost未配置/solrchroot.配置似乎存储在根节点.
所以换行
String zkHostString = "localhost:9983/solr";
Run Code Online (Sandbox Code Playgroud)
至
String zkHostString = "localhost:9983";
Run Code Online (Sandbox Code Playgroud)
你的代码应该有效.