Solr 1.4和Solrj 4.6需要哪些兼容性更改?

时间:2015-02-19 08:35:01

标签: solr solrj solr4

我已将Solrj从1.4升级到4.6,并支持Solr服务器1.4和Solr服务器4。

当我使用Solrj 4.6和Solr服务器1.4执行以下代码时,我得到了异常Invalid version (expected 2, but 1) or the data in not in 'javabin' format

HttpSolrServer server = new HttpSolrServer(baseURL);
try {
    System.out.println(server.ping());;
} catch (SolrServerException | IOException e1) {
}

为了解决这种跨版本的兼容性,在solr wiki中提到将解析器设置为XMLResponseParser。通过此实现,我的代码更改如下:

HttpSolrServer server = new HttpSolrServer(baseURL);
server.setParser(new XMLResponseParser());
try {
    System.out.println(server.ping());;
} catch (SolrServerException | IOException e1) {
}

现在我收到的错误如下:

Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Expected content type application/xml; charset=UTF-8 but got text/xml;charset=UTF-8. <?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">3</int><lst name="params"><str name="fl">*</str><str name="echoParams">all</str><str name="version">2.2</str><str name="echoParams">all</str><str name="q">solrpingquery</str><str name="qt">standard</str><str name="wt">xml</str><str name="version">2.2</str></lst></lst><str name="status">OK</str>
</response>

我请求您帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

根据JIRA(https://issues.apache.org/jira/browse/SOLR-5532),这个错误出现在Solr 4.6

我建议您至少更新Solr 4.6到4.6.1,或者如果可能的话,更新到4.7或甚至更新到4.10。