Solr的API 链接

pom.xml 添加配置

 <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-solrj</artifactId>
            <version>6.5.0</version>
        </dependency> 
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.noggit</groupId>
<artifactId>noggit</artifactId>
<version>0.5</version>
</dependency>

1>建立链接
SolrClient 自从5.0起代替SolrServer类
SolrClient 
Solr的子类     CloudSolrClient, ConcurrentUpdateSolrClient, HttpSolrClient, LBHttpSolrClient
ConcurrentUpdateSolrClient 线程安全 将所有添加的文件缓存到开放的HTTP链接 官方建议用于更新请求
HttpSolrClient 访问Http的方式 用于查询
LBHttpSolrClient Solr集群
(1)已过时 建议第二种
SolrClient client = new HttpSolrClient("http://my-solr-server:8983/solr/core1");
QueryResponse resp = client.query(new SolrQuery("*:*"));
(2)
Builder builder=new HttpSolrClient.Builder("http://my-solr-server:8983/solr/core1");
SolrClient client=builder.build();
QueryResponse resp = client.query(new SolrQuery("*:*"));

出现错误
1》 org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:
服务器地址出现错误 修改配置文件即可  eg: http://192.168.8.141:8983/solr/+coreName(Core的名字)

  详细代码:

Solr的API 链接

运行结果:

Solr的API 链接

相关文章:

  • 2021-06-09
  • 2022-01-10
  • 2021-06-27
  • 2021-06-30
  • 2022-12-23
  • 2021-06-16
  • 2021-09-10
  • 2021-10-19
猜你喜欢
  • 2021-11-26
  • 2021-10-24
  • 2021-12-28
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案