我正在为使用Solrj索引而苦苦挣扎。
我想使用SolrCloud,我将我的连接设置如下:
SolrClient client = new CloudSolrClient.Builder().withSolrUrl("http://localhost:8983/solr/collectioname").build();
我有这个错误。我在这里发帖前检查了evruwhere,但我无法解决它
Exception in thread "main" java.lang.RuntimeException: Couldn't initialize a HttpClusterStateProvider (is/are the Solr server(s), [http://localhost:8983/solr/collectioname], down?)
at org.apache.solr.client.solrj.impl.CloudSolrClient$Builder.build(CloudSolrClient.java:1496)
at indexsolr.<init>(indexsolr.java:29)
at LoadData.toIndex(LoadData.java:100)
at LoadData.loadDocuments(LoadData.java:72)
at IndexLaunch.main(IndexLaunch.java:12)
Caused by: org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/collectioname: Expected mime type application/octet-stream but got text/html. <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/collectioname/admin/collections. Reason:
<pre> Not Found</pre></p>
</body>
</html>
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:607)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:255)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:244)
at org.apache.solr.client.solrj.SolrClient.request(SolrClient.java:1219)
at org.apache.solr.client.solrj.impl.HttpClusterStateProvider.fetchLiveNodes(HttpClusterStateProvider.java:189)
at org.apache.solr.client.solrj.impl.HttpClusterStateProvider.<init>(HttpClusterStateProvider.java:64)
at org.apache.solr.client.solrj.impl.CloudSolrClient$Builder.build(CloudSolrClient.java:1494)
... 4 more
发布于 2018-03-20 05:59:12
正如在前面的回答中提到的,SolrJ使用的URL中没有集合名称(我应该更直接地指出):
final String solrUrl = "http://localhost:8983/solr";
return new HttpSolrClient.Builder(solrUrl)
.withConnectionTimeout(10000)
.withSocketTimeout(60000)
.build();发布于 2018-03-20 14:25:00
对于SolrCloud,您需要使用CloudSolrClient。根据您使用的Solr版本,您可以创建CloudSolrClient对象,也可以使用CloudSolrClient.Builder
发布于 2019-05-26 19:05:05
我就是这么做的。Solr cloud只需要接受一个url列表作为参数,而不仅仅是一个字符串url。
private static final String BASE_SOLR_URL = "http://localhost:8983/solr";
// or initialize a list of solr instances urls
@Bean(name = "solrCloudClient")
public static CloudSolrClient getCloudConnection() {
System.out.println("----Initializing cloud Solr Connection---");
List<String> solrCloudUrls = Arrays.asList(BASE_SOLR_URL); // or list of urls
CloudSolrClient client = new CloudSolrClient.Builder(solrCloudUrls).build();
client.setParser(new XMLResponseParser());
return client;
}https://stackoverflow.com/questions/49370872
复制相似问题