solr文档索引最佳实践
solr文档索引最佳实践
@(OTHERS)[solr]
- solr文档索引最佳实践
- 一直接提交
- 二AutoCommit
- 三 commitWithin
- 四建议及结论
- 1单线程情况
- 2多线程情况
solr的文档生成后,需要将其提交到solr集群,提交的方法有以下三种:
(一)直接提交
每生成一个文档就直接提交至solr:
CloudSolrClient client = new CloudSolrClient(SOLR_ZK);
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField("id", "ljhtest3");
doc2.addField("key_ss", map);
client.add(doc2);
client.commit();
即每add一次就commit一次,这种实现方案实现简单,但性能不高。
* 注意,不只是commit()效率不高,client.add()的效率也是非常低的,因此需要将所有文档先add进一个collection,然后client.add(collection) *
List<SolrInputDocument> docList = new LinkedList<SolrInputDocument>();for (int i = 0; i < DOC_NUM; i++) {SolrInputDocument doc2 = new SolrInputDocument();doc2.addField("id", "way2" + i);Set set = new HashSet();for (String s : "abc,edf,kkk,lll".split(",")) {set.add(s);}Map map = new HashMap();map.put("set", set);doc2.addField("key_ss", map);docList.add(doc2);}client.add(docList);client.commit();
(二)AutoCommit
可以在solrConfig.xml中的updateHandler设置自动提交机制:
<!-- Enables a transaction log, used for real-time get, durability, andand solr cloud replica recovery. The log can grow as big asuncommitted changes to the index, so use of a hard autoCommitis recommended (see below)."dir" - the target directory for transaction logs, defaults to thesolr data directory."numVersionBuckets" - sets the number of buckets used to keeptrack of max version values when checking for re-orderedupdates; increase this value to reduce the cost ofsynchronizing access to version buckets during high-volumeindexing, this requires 8 bytes (long) * numVersionBucketsof heap space per Solr core.
-->
<updateLog><str name="dir">${solr.ulog.dir:}</str><int name="numVersionBuckets">${solr.ulog.numVersionBuckets:65536}</int>
</updateLog><!-- AutoCommitPerform a hard commit automatically under certain conditions.Instead of enabling autoCommit, consider using "commitWithin"when adding documents. http://wiki.apache.org/solr/UpdateXmlMessagesmaxDocs - Maximum number of documents to add since the lastcommit before automatically triggering a new commit.maxTime - Maximum amount of time in ms that is allowed to passsince a document was added before automaticallytriggering a new commit. openSearcher - if false, the commit causes recent index changesto be flushed to stable storage, but does not cause a newsearcher to be opened to make those changes visible.If the updateLog is enabled, then it's highly recommended tohave some sort of hard autoCommit to limit the log size.--><autoCommit> <maxTime>${solr.autoCommit.maxTime:15000}</maxTime> <openSearcher>false</openSearcher> </autoCommit><!-- softAutoCommit is like autoCommit except it causes a'soft' commit which only ensures that changes are visiblebut does not ensure that data is synced to disk. This isfaster and more near-realtime friendly than a hard commit.--><autoSoftCommit> <maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime> </autoSoftCommit>
可以指定多长时间间隔或者多少文档就会提交一次。
有hard & soft2种,后者不会将数据同步到disk。
(三) commitWithin
client.add(DEFAULT_COLLECTION, doc,1000);
client.add()的文档会在1000ms内被提交到solr中。
(四)建议及结论
1、单线程情况
1、将需要提交的文档add到一个collection中。
2、client add这个collection,而不是add文档 。
3、client指定commitWithin参数。
参考代码如下:
List<SolrInputDocument> docList = new LinkedList<SolrInputDocument>();for (int i = 0; i < DOC_NUM; i++) {SolrInputDocument doc2 = new SolrInputDocument();doc2.addField("id", "way2" + i);Set set = new HashSet();for (String s : "abc,edf,kkk,lll".split(",")) {set.add(s);}Map map = new HashMap();map.put("set", set);doc2.addField("key_ss", map);docList.add(doc2);}client.add(docList);client.commit();
2、多线程情况
(1)hbase写时要有多线程
(2)coprocessor会在多个分区中并行执行。
solr文档索引最佳实践相关推荐
- 公开发布版的Windows Azure 基础结构服务中的 SQL Server – 文档和最佳实践(已更新),还有即将发布的博客...
一周前,WindowsAzure 刚刚宣布公开发布版的基础结构服务正式推出, 这标志着WindowsAzure从此开始完全支持基础结构即服务,SQL Server是其中的一个主要组件. 预安装的SQL ...
- 15 Rest高级客户端实践(一):文档索引
文章目录 1 准备工作 2 前置API介绍 2.1 如何构建高级客户端 2.2 如何构建json文档(数据) 3 索引文档 3.1 如何构建IndexRequest 3.2 执行请求 3.2.1 同步 ...
- Go语言国际电子表格文档格式标准实践
在 Gopher Meetup 北京站上,阿里巴巴高级开发工程师.前百度 Go 语言编程委员会成员续日进行了主题为<Go语言国际电子表格文档格式标准实践>的演讲. Excelize 是 G ...
- Typora markdown公式换行等号对齐_Typora-编写博客格式化文档的最佳软件
Typora-编写博客格式化文档的最佳软件 Typora 不仅是一款支持实时预览的 Markdown 文本编辑器,而且还支持数学公式.代码块.思维导图等功能.它有 OS X.Windows.Linux ...
- in 用不用索引_MySQL 索引最佳实践之问题反馈
我之前发布的 PPT -- <MySQL 索引最佳实践>中,有很多人提了很多问题,我没有时间一一回答,于是我决定把这些问题集中在一起进行回答. 问:我们团队中的一人想要使用 bigint ...
- mysql explain 索引_MySql中Explain详解与索引最佳实践
使用EXPLAIN关键字可以模拟优化器执行SQL语句,从而知道MySQL是 如何处理你的SQL语句的.分析你的查询语句或是结构的性能瓶颈 下面是使用 explain 的例子: 在 select 语句之 ...
- Typora markdown公式换行等号对齐_Typora编写博客格式化文档的最佳软件
Typora-编写博客格式化文档的最佳软件 Typora 不仅是一款支持实时预览的 Markdown 文本编辑器,而且还支持数学公式.代码块.思维导图等功能.它有 OS X.Windows.Linux ...
- HTML 文档可以映射为,将PDF文档转换为可通过URL访问的HTML文档的最佳方法
许多人想了解如何将PDF文档转换为可通过URL访问的HTML文档.毕竟,在线发布PDF文档是与他人共享文档的最佳方法,但是,许多程序都不能完成此操作.因此,本文提出万兴PDF这款出色的解决工具,该程序 ...
- typroa 思维导图_Typora-编写博客格式化文档的最佳软件
Typora-编写博客格式化文档的最佳软件 Typora 不仅是一款支持实时预览的 Markdown 文本编辑器,而且还支持数学公式.代码块.思维导图等功能.它有 OS X.Windows.Linux ...
最新文章
- 关于SQL语言的初步认识
- python基础8(来自廖雪峰的官方网站)
- python国产_Python勒索软件来袭,国产杀软集体失身
- Light-Head R-CNN相关资料
- ElasticSearch探索之路(三)分布式原理:分布式路由、存储、搜索原理
- mysql模糊查询指定根据第几个字符来匹配
- 练习mvc做一个知识库(二)
- java语言复制数组的四种方法
- 游戏开发筑基之用“*“输出三角形(一个for循环)及打印控制台进度条
- linux环境中,检查是否安装某个软件包的几种查看方式
- Cglib动态代理实现方式
- linux 防火墙 卸载不了怎么办,CentOS 7卸载firewalld防火墙安装iptables
- “AI复活了我的妻子,但我决定跟她说再见了”
- 计算单目标跟踪器的平均CLE
- 江城如画里,山晚望晴空。 两水夹明镜,双桥落彩虹。 人烟寒橘柚,秋色老梧桐。谁念北楼上,临风怀谢公
- 易文档(yidocs),更简单的markdown静态文档生成模板
- 使用vant中的地址编辑组件
- c语言函数未定义的引用,c – CMake“未定义的函数引用”
- 那些年,我们一起做过的 Java 课后练习题(26 - 30)
- 计算机网络-实验四:配置网络路由
热门文章
- 【一起去大厂系列】深入理解MySQL中where 1 = 1的用处
- 天平应什么放置_天平是否应该放干燥剂?
- 用java正则表达式验证字符串(邮箱与网址)
- word排版案例报告_停工不停学丨项目部开展Word办公软件使用技能培训
- 基于android的视频采集系统的设计与实现,基于Android的视频通话系统的设计与实现.docx...
- 报考python工程师要求_国家认证的Python技术工程师有什么能力要求?
- a73*2+a53*2指的是什么_什么言四字词
- pool python 传参数_Python-爬虫-多线程、线程池模拟(urllib、requests、UserAgent、超时等)...
- 学业水平考试网登录_2019山东高中学业水平考试报名系统入口http://xysp.sdzk.cn
- 深度学习tensorflow框架的会话