手机版
你好,游客 登录 注册
背景:
阅读新闻

Solr4.6从数据库导数据的步骤

[日期:2014-01-04] 来源:Linux社区  作者:bruce128 [字体:大 中 小]

Solr4.6有从数据库导数据的功能。导入步骤如下:

1.将下载下来的solr4.6的dist文件夹下的solr-dataimporthandler-4.6.0.jar和solr-dataimporthandler-extras-4.6.0.jar放入tomcat该路径下:F:\solr\tomcat7.0.27\webapps\solr\WEB-INF\lib

2.修改solrconfig.xml,添加下面这段代码:

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
          <lst name="defaults">
              <str name="config">data-config.xml</str>
          </lst>
 </requestHandler>

3.然后再solrconfig.xml文件统计的目录下新增上面声明的data-config.xml。内容如下:

<?xml version="1.0" encoding="UTF-8" ?>

<dataConfig>
  <dataSource type="JdbcDataSource"
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://10.28.174.65:3306/chat_dev?useUnicode=true&characterEncoding=GBK"
              user="chat_write"
              password="123456"/>
  <document>
  <entity name="id" query="select id, cid, serviceid, customer, content from chatlogs_jad"></entity>
  </document>

</dataConfig>

4.修改schema.xml,修改数据类型定义:

 <fields>
  <field name="_version_" type="long" indexed="true" stored="true"/>
  <field name="_root_" type="string" indexed="true" stored="false"/>
 
    <field name="id" type="int" stored="true" indexed="true"/>
 <field name="cid" type="string" stored="true" indexed="true"/>
 <field name="serviceid" type="string" stored="true" indexed="true"/>
 <field name="customer" type="string" stored="true" indexed="true"/>
 <field name="content" type="string" stored="true" indexed="true"/>
</fields>

注意,_root_和_version_是必备的,不能少,少了就报错!

5.重启tomcat。

6.在管理员界面上执行操作:

Solr4.6从数据库导数据的步骤

配置好参数后,点击execute按钮即可!可以看出,5分半中之内传了17W条数据,蛮高兴的。

Solr 的详细介绍:请点这里
Solr 的下载地址:请点这里

相关阅读:

Solr3.6.1 在Tomcat6下的环境搭建 http://www.linuxidc.com/Linux/2013-01/77664.htm

基于Tomcat的Solr3.5集群部署 http://www.linuxidc.com/Linux/2012-12/75297.htm

在Linux上使用Nginx为Solr集群做负载均衡 http://www.linuxidc.com/Linux/2012-12/75257.htm

Linux下安装使用Solr http://www.linuxidc.com/Linux/2012-10/72029.htm

在 Ubuntu 12.04 LTS 上通过 Tomcat 部署 Solr 4 http://www.linuxidc.com/Linux/2012-09/71158.htm

Solr实现Low Level查询解析(QParser) http://www.linuxidc.com/Linux/2012-05/59755.htm

基于Solr 3.5搭建搜索服务器 http://www.linuxidc.com/Linux/2012-05/59743.htm

Solr 3.5开发应用教程 PDF高清版 http://www.linuxidc.com/Linux/2013-10/91048.htm

Solr 4.0 部署实例教程 http://www.linuxidc.com/Linux/2013-10/91041.htm

linux
相关资讯       Solr  Solr4.6 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款