添加数据时的SolrJ错误

SolrJ error when adding data

我正在尝试在 Java 中以编程方式启动 Solr 服务器,并且我正在使用官方教程中的资源。我的代码是:

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

SolrInputDocument document = new SolrInputDocument();
document.addField("id", "552199");
document.addField("name", "Gouda cheese wheel");
document.addField("price", "49.99");
UpdateResponse response = solr.add(document);


solr.commit();

问题是我既不能以编程方式启动服务器(我是通过命令提示符启动的)而且我得到了这个错误:

 Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr: Expected mime type application/octet-stream but got text/html. <html>

知道发生了什么以及我该如何解决吗?

我认为您的 urlString 不正确,需要添加您的核心名称,例如:

必须使用 核心 指定字符串 URL。如下

String urlString = "http://localhost:8983/solr/Core_name";