solr从mysql导入数据库_Solr从数据库导入数据

一. 数据导入(DataImportHandler-DIH)

DIH 是solr 提供的一种针对数据库、xml/HTTP、富文本对象导入到solr 索引库的工具包。这里只针对数据库做介绍。

A、准备以下jar包

apache-solr-dataimporthandler-4.0.0.jar

apache-solr-dataimporthandler-extras-4.0.0.jar

apache-solr-dataimportscheduler-1.1.jar(增量导入使用)

数据库对应的jdbc驱动包这里使用的是Oracle oracle10g.ja放入Tomcat6.0.36/webapps/sol/WEB-INF/lib 中

B、配置solrconfig.xml

在solrconfig.xml中加入如下配置:

xx-data-config.xml

C、配置数据源

在与solrconfig.xml文件同级的目录中建立上述配置中的xx-data-config.xml文件,配置如下

86d60108d008d4b88e3912bd30b31cd5.png

query属性为全导入的时候使用。其他为增量导入使用。

driver=”oracle.jdbc.driver.OracleDriver”

url=”jdbc:oracle:thin:@192.168.0.129:1521:orcl”

user=”username”

password=”password”/>

query=”select t.ID id,business_name,bussiness_type from business t”

deltaImportQuery=”select t.ID id,business_name,bussiness_type from business t where id=’${dataimporter.delta.ID}’”

deltaQuery=”select t.ID id,business_name,bussiness_type from business t where  to_char(updatetime,’yyyy-mm-dd hh24:mi:ss’)> ’${dataimporter.last_index_time}’”>

至此所有DIH的配置完成,在浏览器中输入命令:

全导入:

http://localhost:8085/solr/core0/dataimport?command=full-import&commit=ture

增量导入:

http://localhost:8085/solr/core0/dataimport?command=delta-import&clean=false&commit=ture

查看导入状态

http://localhost:8085/solr/core0/dataimport?command=status

D、处理CLOB字段

ClOB 字段的 column 必须大写!!

E、DIH内存溢出错误

在使用DIH时,容易报内存溢出错误。可以通过设置jvm大小来解决。设置方法如下:

在tomcat\bin\startup.bat 加入SET JAVA_OPTS=-Xms128m -Xmx1024m 配置 这里设置的是1024M,根据情况可以适量增大

F、自动全导入和自动增量导入

此功能可以自己写程序实现,也可利用apache-solr-dataimportscheduler-1.0.jar包完成此功能。配置如下:

修改solr.war中WEB-INF/web.xml, 在servlet节点前面增加:

org.apache.solr.handler.dataimport.scheduler.ApplicationListener

将apache-solr-dataimportscheduler-.jar 中 dataimport.properties 取出并根据实际情况修改,然后放到 solr.home/conf (不是solr.home/core/conf) 目录下面

作者:awj3584 发表于2013-12-10 14:44:57 原文链接

阅读:100 评论:0 查看评论

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值