solrj 测试连接 6.6.5solr集群
我开始环境是
linux上是6.6.5 pom也是6.6.5
按照学习视频的demo,他用的是4点几的solr,我换成了6点几的,没有CloudSolrServer 只有CloudSolrClient
然后看源码的构造方法,写出了第一版
@Test
public void testAddDocument() throws Exception {
//创建一个集群的连接,应该使用CloudSlorServer创建
CloudSolrClient cloudSolrClient = new CloudSolrClient("192.168.25.134:2181,192.168.25.134:2182,192.168.25.134:2183"); //zkHost:zookeeper的地址列表
//设置一个defaultCollection属性
cloudSolrClient.setDefaultCollection("collection2");//Solr管理界面Graph的那个collection
//创建一个文档对象
SolrInputDocument document = new SolrInputDocument();
//向文档中添加域
document.setField("id", "solrcloud01");
document.setField("item_title", "测试商品01");
document.setField("item_price", );
//把文档写入索引库
cloudSolrClient.add(document);
//提交
cloudSolrClient.commit();
cloudSolrClient.close();
}
java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.MDC
at org.apache.solr.common.SolrException.<init>(SolrException.java:)
at org.apache.solr.common.cloud.SolrZkClient.<init>(SolrZkClient.java:)
at org.apache.solr.common.cloud.SolrZkClient.<init>(SolrZkClient.java:)
at org.apache.solr.common.cloud.SolrZkClient.<init>(SolrZkClient.java:)
at org.apache.solr.common.cloud.ZkStateReader.<init>(ZkStateReader.java:)
at org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider.connect(ZkClientClusterStateProvider.java:)
at org.apache.solr.client.solrj.impl.CloudSolrClient.connect(CloudSolrClient.java:)
at org.apache.solr.client.solrj.impl.CloudSolrClient.requestWithRetryOnStaleState(CloudSolrClient.java:)
at org.apache.solr.client.solrj.impl.CloudSolrClient.request(CloudSolrClient.java:)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:)
at com.fighting.solrj.TestSolrCloud.testAddDocument(TestSolrCloud.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.junit.runners.model.FrameworkMethod$.runReflectiveCall(FrameworkMethod.java:)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:)
at org.junit.runners.ParentRunner$.run(ParentRunner.java:)
at org.junit.runners.ParentRunner$.schedule(ParentRunner.java:)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:)
at org.junit.runners.ParentRunner.access$(ParentRunner.java:)
at org.junit.runners.ParentRunner$.evaluate(ParentRunner.java:)
at org.junit.runners.ParentRunner.run(ParentRunner.java:)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:)

报错,说是slf4j的错误,然后百度,只有stackoverflow的两个链接 ,而且没有解决方法
而且我也感觉不是slf4j的问题
然后继续百度 看看有没有其他方法
第二版
@Test
public void testAddDocument() throws Exception {
//创建一个集群的连接,应该使用CloudSlorServer创建
//CloudSolrClient cloudSolrClient = new CloudSolrClient("192.168.25.134:2181,192.168.25.134:2182,192.168.25.134:2183");
List<String> zkHosts = new ArrayList<String>();
zkHosts.add("192.168.25.134:2181");
zkHosts.add("192.168.25.134:2182");
zkHosts.add("192.168.25.134:2183"); CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHosts).build();
//zkHost:zookeeper的地址列表
//设置一个defaultCollection属性
cloudSolrClient.setDefaultCollection("collection2");//Solr管理界面Graph的那个collection
//创建一个文档对象
SolrInputDocument document = new SolrInputDocument();
//向文档中添加域
document.setField("id", "solrcloud01");
document.setField("item_title", "测试商品01");
document.setField("item_price", );
//把文档写入索引库
cloudSolrClient.add(document);
//提交
cloudSolrClient.commit();
cloudSolrClient.close();
}
还是上面那个报错
然后看了搜了搜开源项目 也没用连接集群的
网上只有一个版本是7.4.0 的
linux上solr集群的环境没变,把pom中solrj的版本给为7.4.0
使用他的方法
//创建一个集群的连接,应该使用CloudSlorServer创建
//CloudSolrClient cloudSolrClient = new CloudSolrClient("192.168.25.134:2181,192.168.25.134:2182,192.168.25.134:2183");
List<String> zkHosts = new ArrayList<String>();
zkHosts.add("192.168.25.134:2181");
zkHosts.add("192.168.25.134:2182");
zkHosts.add("192.168.25.134:2183");
Optional<String> zkChroot = Optional.of("/");
//CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHosts).build();
Builder builder = new CloudSolrClient.Builder(zkHosts, zkChroot);
CloudSolrClient cloudSolrClient = builder.build();
//zkHost:zookeeper的地址列表
//设置一个defaultCollection属性
cloudSolrClient.setDefaultCollection("collection2");//Solr管理界面Graph的那个collection
//创建一个文档对象
SolrInputDocument document = new SolrInputDocument();
//向文档中添加域
document.setField("id", "solrcloud01");
document.setField("item_title", "测试商品01");
document.setField("item_price", 123);
//把文档写入索引库
cloudSolrClient.add(document);
//提交
cloudSolrClient.commit();
cloudSolrClient.close();
没报错 查询也有数据了
solrj 测试连接 6.6.5solr集群的更多相关文章
- 使用SolrJ客户端管理SolrCloud(Solr集群)
1.使用SolrJ客户端管理SolrCloud(Solr集群). package com.taotao.search.service; import java.io.IOException; impo ...
- Pentaho Kettle 6.1连接CDH5.4.0集群
作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 欢迎转载 最近把之前写的Hadoop MapReduce程序又总结了下,发现很多逻辑基本都是大致相同的,于是想到 ...
- 搭建和测试 Redis 主备和集群
本文章只是自我学习用,不适宜转载. 1. Redis主备集群 1.1 搭建步骤 机器:海航云虚机(2核4GB内存),使用 Centos 7.2 64bit 操作系统,IP 分别是 192.168.10 ...
- YCSB测试HBase远程完全分布式集群
写在前面 本文只讲一个很简单的问题,YCSB对HBase集群的测试.虽然网上有很多介绍YCSB测试HBase的文章,但都是针对本地HBase伪分布式集群的.大家都知道,稍微正式一些的压测都会要求测试客 ...
- 测试环境docker化—容器集群编排实践
本文来自网易云社区 作者:孙婷婷 背景 在前文<测试环境docker化-基于ndp部署模式的docker基础镜像制作>中已经详述了docker镜像制作及模块部署的过程,按照上述做法已可以搭 ...
- 腾讯云轻量服务器通过Docker搭建外网可访问连接的redis5.x集群
总结记录/朱季谦 最近买了一台4核16的腾讯云轻量应用服务器,花了我快四百的大洋,打算搭建一堆docker组件集群,最先开始是通过docker搭建redis集群,计划使用三个端口,分别是7001,70 ...
- python连接redis,redis集群
python连接redis: import redis r = redis.Redis(host='192.168.50.181',port=6002) r.set('user_phone_14900 ...
- 使用Hbase快照将数据输出到互联网区测试环境的临时Hbase集群
通过snapshot对内网测试环境Hbase生产集群的全量数据(包括原始数据和治理后数据)复制到互联网Hbase临时集群.工具及原理: 1) Hbase自带镜像导出工具(snapsho ...
- 云原生 PostgreSQL - CrunchyData PGO 教程:创建、连接、删除 Postgres 集群
入门 作为安装的一部分,请确保您已完成以下操作: 分叉 Postgres Operator 示例存储库并将其克隆到您的主机. https://github.com/CrunchyData/postgr ...
随机推荐
- JSON数据的解析和生成(Swift)
Codable public typealias Codable = Decodable & Encodable public protocol Decodable {} public pro ...
- 简单步骤Centos7安装Tomcat 8 (yum安装)(ZT)
原文:https://blog.51cto.com/bestlope/1978114?source=drt 说明: 操作系统:Centos7 系统环境:未安装其他服务 Step 1:更新系统 sudo ...
- [福大2018高级软工教学]团队Beta阶段成绩汇总
一.作业地址: https://edu.cnblogs.com/campus/fzu/AdvancedSoftwareEngineerning2018/homework/2465 二.Beta阶段作业 ...
- 15.过滤器-基础.md
目录 基础 实例 图解 核心API interface Filter过滤器接口 interface FilterConfig获取过滤器初始化信息 interface FilterChain 过滤器参数 ...
- 吴裕雄 28-MySQL 序列使用
MySQL序列是一组整数:1, 2, 3, ...,由于一张数据表只能有一个字段自增主键, 如果你想实现其他字段也实现自动增加,就可以使用MySQL序列来实现 使用AUTO_INCREMENTMySQ ...
- 前往央都之行-gdufe1529
前往央都之行 Time Limit: 2000/1000ms (Java/Others) Problem Description: 刀光哥桐人和尤吉欧两人为了拯救爱丽丝,同时从卢利特村出发要尽快同时赶 ...
- Oracle数据库操作总是显示运行中无法成功,删除表时报错 resource busy and acquire with NOWAIT specified
1.直接运行以下语句: select t2.username,t2.sid,t2.serial#,t2.logon_timefrom v$locked_object t1,v$session t2wh ...
- devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free data blocks. Create more free space in thin pool or use dm.min_free_space option to change behavior
问题: 制作镜像的时候报错 devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 1 ...
- ggplot2
应用与: http://www.cnblogs.com/batteryhp/p/5232353.html 由于python中matplotlib包的画图功能比较基本,不怎么炫酷,所以想用R中的ggpl ...
- poi excel 加粗
参考 https://blog.csdn.net/wellto/article/details/52293202 XSSFWorkbook xwb = new XSSFWorkbook(); ... ...