一、添加

@Test
public void testAddDocument() throws Exception{
//创建一个集群的连接,应该使用 CloudSolrServer,//zkHost:zookeeper 的地址表
String zkHost = "192.168.25.129:2181,192.168.25.129:2182,192.168.25.129:2183";
CloudSolrServer solrServer = new CloudSolrServer(zkHost);
//设置一个 defaultCollection 属性
solrServer.setDefaultCollection("collection2"); //创建一个文档对象
SolrInputDocument document = new SolrInputDocument();
//向文档中添加域
document.setField("id", "01");
document.setField("name", "jack"); //创建一个文档对象
SolrInputDocument document2 = new SolrInputDocument();
//向文档中添加域
document2.setField("id", "02");
document2.setField("name", "rose"); //把文档写入索引库
solrServer.add(document);
solrServer.add(document2);
//提交
solrServer.commit(); }

 二、查询

@Test
public void testQuerryDocument() throws Exception{
//创建一个集群的连接,应该使用 CloudSolrServer,//zkHost:zookeeper 的地址表
String zkHost = "192.168.25.129:2181,192.168.25.129:2182,192.168.25.129:2183";
CloudSolrServer solrServer = new CloudSolrServer(zkHost);
//设置一个 defaultCollection 属性
solrServer.setDefaultCollection("collection2"); //创建一个查询对象
SolrQuery query = new SolrQuery();
//设置查询条件
query.setQuery("*:*");
//执行查询
QueryResponse response = solrServer.query(query);
//获取查询结果
SolrDocumentList list = response.getResults(); System.out.println("总记录数"+ list.getNumFound()); for (SolrDocument solrDocument : list) {
System.out.println(solrDocument.get("id"));
System.out.println(solrDocument.get("name"));
}
}

 三、参考

  http://www.cnblogs.com/fangwu/p/8652945.html

solrj 操作 solr 集群版的更多相关文章

  1. Solr 14 - SolrJ操作SolrCloud集群 (Solr的Java API)

    目录 1 pom.xml文件的配置 2 SolrJ操作SolrCloud 1 pom.xml文件的配置 项目的pom.xml依赖信息请参照: Solr 09 - SolrJ操作Solr单机服务 (So ...

  2. solrcloud(solr集群版)安装与配置

    1 Solr集群 1.1 什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud.当一个系统的 ...

  3. Solr 13 - 在URL地址栏中操作Solr集群 - 包括CRUD、别名、切割分片、更新配置

    目录 1 创建操作 1.1 创建collection 1.2 创建core 1.3 创建操作中的参数 2 删除操作 3 加载操作 4 查看操作 5 操作集合别名(操作成功, 但未查出区别) 6 切割分 ...

  4. solr java api 使用solrj操作zookeeper集群中的solrCloud中的数据

    1 导入相关的pom依赖 <dependencies> <dependency> <groupId>org.apache.solr</groupId> ...

  5. solr集群与项目实战

    什么是 SolrCloud : SolrCloud(solr 云)是 Solr 提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud.当一个系统的索引数据量少的时 ...

  6. Solr集群—SolrCloud

    1.   学习计划 1.solr集群搭建 2.使用solrj管理solr集群 3.把搜索功能切换到集群版 2.   什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜 ...

  7. JAVAEE——宜立方商城08:Zookeeper+SolrCloud集群搭建、搜索功能切换到集群版、Activemq消息队列搭建与使用

    1. 学习计划 1.solr集群搭建 2.使用solrj管理solr集群 3.把搜索功能切换到集群版 4.添加商品同步索引库. a) Activemq b) 发送消息 c) 接收消息 2. 什么是So ...

  8. 使用jedis客户端连接redis,单机版和集群版

    单机版 1.入门实例 @Test public void testJedis(){ //创建一个jedis对象,需要指定服务的ip和端口号 Jedis jedis=new Jedis("19 ...

  9. solrcloud集群版的搭建

    说在前面的话 之前我们了解到了solr的搭建,我们的solr是搭建在tomcat上面的,由于tomcat并不能过多的承受访问的压力,因此就带来了solrcloud的时代.也就是solr集群. 本次配置 ...

随机推荐

  1. GitLab 7.5.3 CentOS7安装和SMTP配置

    CentOS 7安装GitLab还是比較简单的,依照官方文档的提示一步一步操作下来.就一个地方须要改动. 參考:GitLab安装说明 在安装好以后,执行 gitlab-ctl reconfigure ...

  2. Spring技术内幕:SpringIOC原理学习总结

    前一段时候我把Spring技术内幕的关于IOC原理一章看完,感觉代码太多,不好掌握,我特意又各方搜集了一些关于IOC原理的资料,特加深一下印象,以便真正掌握IOC的原理. IOC的思想是:Spring ...

  3. visual studio 开发工具SVN集成工具,测试可用,成功集成

    使用说明:https://www.xiazaiba.com/html/24864.html 下载地址:点击下载集成插件

  4. cocos2dx 自己主动绑定js

    依照教程把全部资源下载好后....... 找到cocos2dx project下的tools/bindings-generator/test 发现里面有test.sh , test.ini , 去掉s ...

  5. nyoj--635--Oh, my goddess(dfs)

    Oh, my goddess 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice an ...

  6. [HTML&CSS] 条件注释判断浏览器

    <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...

  7. ES6 Proxy 性能之我见

    ES6 Proxy 性能之我见 本文翻译自https://thecodebarbarian.com/thoughts-on-es6-proxies-performance Proxy是ES6的一个强力 ...

  8. 关于Html基础语法学习

    晚上做完初赛,好像有点颓,就来学了学html,毕竟博客里面会用到嘛. 首先贴出我所学习的教程 http://www.w3school.com.cn/html/index.asp 我觉得吧,可能以我的记 ...

  9. History of the browser user-agent string--转

    https://webaim.org/blog/user-agent-string-history/ In the beginning there was NCSA Mosaic, and Mosai ...

  10. C#使用ICSharpCode.SharpZipLib.dll进行文件的压缩与解压

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...