Solr4.8.1从Mysql数据库导数据的步骤

来源:互联网 发布:单片机串口工作原理 编辑:程序博客网 时间:2024/06/01 11:53


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

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

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

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

 3.然后再solrconfig.xml文件的同目录下新增上面声明的data-config.xml。内容如下:
<dataConfig>  <dataSource type="JdbcDataSource"               driver="com.mysql.jdbc.Driver"               url="jdbc:mysql://10.28.174.65:3306/test?useUnicode=true&characterEncoding=utf-8"               user="root"               password="123456"/>   <document>   <entity name="id" query="select id, cid, serviceid, customer, content from chatlogs_jad"></entity>   </document> </dataConfig>
4.修改schema.xml,修改数据类型定义:
    <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"/>

 注意,_root_和_version_是必备的,不能少,少了就报错!(_version_有些已经自带不能重复否则报错)

5.重新上传配置文件solrconfig.xml, schema.xmml,data-config.xml

(1)上传solr配置文件

java -classpath .:/home/hadoop/liao/tomcat/webapps/solr/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost master:2181,slave0:2181,slave1:2181,slave2:2181,slave3:2181 -confdir  /home/hadoop/liao/solr-home/db/conf -confname myconf
我的配置文件在
/home/hadoop/liao/solr-home/db/conf
根据每个人的情况自己重新上传

2)将上传的配置文件和collection联系起来

java -classpath .:/home/hadoop/liao/tomcat/webapps/solr/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection mycollection -confname myconf -zkhost master:2181,slave0:2181,slave1:2181,slave2:2181,slave3:2181

6.重启tomcat。

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




0 0