SolrJ
版本7.5,Solr版本7.5。查询测试代码如下:
class="java">
HttpSolrClient solr = new HttpSolrClient.Builder(solrUrl).build();
solr.setParser(new DelegationTokenResponse.JsonMapResponseParser());
SolrQuery query=new SolrQuery();
query.set("q","title:"+queryStr);
query.set("wt","json");
try {
QueryResponse solrResponse=solr.query(query );
SolrDocumentList results = solrResponse.getResults();
System.out.println(results.toString());
} catch (SolrServerException e) {
e.printStackTrace();
}
执行抛出
异常信息:
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://127.0.0.1:8983/solr/xxxxxx: Expected mime type application/json but got text/plain
经过一番苦苦搜索,原因居然出在 solr-7.5.0/server/solr/${core}/conf/solrconfig.xml
该配置文件中有如下配置:
<queryResponseWriter name="json" class="solr.JSONResponseWriter">
<!-- For the purposes of the tutorial, JSON responses are written as
plain text so that they are easy to read in *any* browser.
If you expect a MIME type of "application/json" just remove this override.
-->
<str name="content-type">text/plain; charset=UTF-8</str>
</queryResponseWriter>
各位请注意看
注释里面的那段话!!!
将text/plain 修改为 application/json 运行一切正常。