Solr7正确的调用SolrClient姿势

好多文章习惯这么调用SolrClient:

final String solrUrl = "http://localhost:8983/solr/solr_core";
HttpSolrClient client = new HttpSolrClient.Builder(solrUrl)
        .withConnectionTimeout(10000)
        .withSocketTimeout(60000)
        .build();
//查询
//.............
final QueryResponse response = client.query(queryParams);
//新增
//.............
client.add(document);
client.commit();         

这种方式在main方法测试中没什么问题,如果通过SpringBoot进行客户端注入调用就会报错:org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/new_core: Expected mime type application/octet-stream but got text/html
通过查询官方案例,正确的调用姿势如下:

final String solrUrl = "http://localhost:8983/solr/";
final String solrCore = "solr_core";
HttpSolrClient client = new HttpSolrClient.Builder(solrUrl)
        .withConnectionTimeout(10000)
        .withSocketTimeout(60000)
        .build();
//查询
//.............
final QueryResponse response = client.query(solrCore,queryParams);
//新增
//.............
client.add(solrCore,document);
client.commit(solrCore);         

你可能感兴趣的:(Solr)