Solr7.4集群导入MySQL的数据

1、将

/usr/local/solr/solr-7.2.1/dist/

jar包 复制到

/usr/local/solr/tomcat/apache-tomcat-8.5.34-8081/webapps/solr/WEB-INF/lib/

 

2、将mysql的jar包

复制到

/usr/local/solr/tomcat/apache-tomcat-8.5.34-8081/webapps/solr/WEB-INF/lib/

3、在搭建集群时上传到zookeeper的配置文件目录中新增data-config.xml

  上传zookeeper的conf如下

/usr/local/solr/solr_home8081/configsets/sample_techproducts_configs/conf/

4、配置文件如下:

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://10.1.2.52:3306/mktinfo" user="root" password="9fstock" />
    <document>
        <entity name="asset_info" query="SELECT stk_code,stk_name,stk_name_long,spelling_abbr,spelling FROM asset_info">
			<field column="stk_code" name="stkCode" />
			<field column="stk_name" name="stkName" />
			<field column="stk_name_long" name="stkNameLong" />
			<field column="spelling_abbr" name="spellingAbbr" />
			<field column="spelling" name="spelling" />
        </entity>
    </document>
</dataConfig>

 5、在

/usr/local/solr/solr_home8081/configsets/sample_techproducts_configs/conf/managed-schema

中添加如下配置,注意该字段name和data-config.xml中的name="stkCode" 要一致

 

<uniqueKey>stkCode</uniqueKey>

 

注意uniqueKey中的stkCode和<field name="stkCode" type="string" indexed="true" stored="true" required="true" />中的required="true" 保持一致。用唯一性的字段表示。

 

<field name="spelling" type="string" indexed="true" stored="true"/>
<field name="spellingAbbr" type="string" indexed="true" stored="true"/>
<field name="stkCode" type="string" indexed="true" stored="true" required="true" />
<field name="stkName" type="string" indexed="true" stored="true"/>
<field name="stkNameLong" type="string" indexed="true" stored="true"/>

6、在

/usr/local/solr/solr_home8081/configsets/sample_techproducts_configs/conf/solrconfig.xml

 中添加

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

7、执行如下命令,重新将如下文件提交到zookpeer上

./zkcli.sh -zkhost 192.168.25.128:2181,192.168.25.128:2182,192.168.25.128:2183 -cmd upconfig -confdir /usr/local/solr/solr_home8081/configsets/sample_techproducts_configs/conf -confname myconf

8、查看zookeeper中是否有更新

9、接下来导入数据 

 

刷新状态

 

10、查询有数据返回

 

参考:https://blog.csdn.net/lhc0512/article/details/82315354

参考:https://blog.csdn.net/jaffreyen/article/details/78966429  手动页面添加数据

posted on 2018-10-15 14:16  腾飞的鹰  阅读(470)  评论(1)    收藏  举报

导航