标签:
1、将solr-dataimporthandler-4.10.4.jar、mysql-connector-java-5.1.23.jar拷贝到/WEB-INF/lib/下
2、修改home\solr\collection1\conf\solrconfig.xml、schema.xml,创建data-config.xml
solrconfig.xml增加以下内容:
<!-- add by sniper 数据导入,全量索引 -->
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
schema.xml增加以下内容:
id、name使用自带的:
<field name="nickName" type="text_ik" indexed="true" stored="true"/>
data-config.xml内容如下:
<dataConfig>
<dataSource name="jdbc" type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/my"
user="root" password="123456"/>
<document name="my_data">
<entity name="test_data"
pk="c_id"
query="select c_id, c_name, c_nickName from t_test limit ${dataimporter.request.begin}, ${dataimporter.request.length}"
deltaImportQuery="select * from t_test where c_id=‘${dataimporter.delta.c_id}‘"
deltaQuery="select c_id from t_test where c_updatetime > ‘${dataimporter.last_index_time}‘"
>
<field column="c_id" name="id" />
<field column="c_name" name="name" />
<field column="c_nickName" name="nickName" />
</entity>
</document>
</dataConfig>
增量执行的时候,会自动生成dataimport.properties,记录上次执行时间,如下:
#Sat Sep 05 17:50:21 CST 2015
test_data.last_index_time=2015-09-05 17\:50\:20
last_index_time=2015-09-05 17\:50\:20
‘${dataimporter.last_index_time}从dataimport.properties文件取得上次执行时间,可以根据该时间自定义sql,实现增量更新
3、启动tomcat
4、在浏览器访问:
http://localhost:8080/solr/collection1/dataimport?command=delta-import&clean=true
5、或者在页面操作:
标签:
原文地址:http://my.oschina.net/sniperLi/blog/501432