导入配置可参考官网:http://lucene.apache.org/solr/guide,http://lucene.apache.org/solr/guide/7_7/
1、创建field,修改managed-schema文件,添加字段信息
<field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/> <field name="code" type="strings" uninvertible="true" indexed="true" stored="true"/> <field name="name" type="text_ik" uninvertible="true" indexed="true" stored="true"/> <field name="remark" type="text_ik" uninvertible="true" indexed="true" stored="true"/> <field name="usable" type="boolean" uninvertible="true" indexed="true" stored="true"/> <field name="addr" type="text_it" uninvertible="true" indexed="true" stored="true"/> <field name="age" type="pint" uninvertible="true" indexed="true" stored="true"/> <field name="birthday" type="pdate" uninvertible="true" indexed="true" stored="true"/> <field name="deptId" type="pint" uninvertible="true" indexed="true" stored="true"/> <field name="createTime" type="pdate" uninvertible="true" indexed="true" stored="true"/>
也可以通过url添加,两种添加方式是等效的,url添加的字段会写入managed-schema文件中
2、修改solrconfig.xml文件,添加配置
<requestHandler name="/import" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">db-config.xml</str> </lst> </requestHandler>
3、在同目录创建db-config.xml文件
<?xml version="1.0" encoding="UTF-8" ?> <dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://39.97.174.153:3306/zhi_test?characterEncoding=utf8" user="root" password="root"/> <document> <entity name="dept" query="select id,code,name,remark,create_time from dept"> <field column="create_time" name="createTime"/> </entity> <entity name="person" query="select * from person" deltaQuery="select id from person where create_time>'${dataimporter.last_index_time}'" deltaImportQuery="select * from person where id='${dih.delta.id}'"> <field column="dept_id" name="deptId"/> <field column="create_time" name="createTime"/> </entity> </document> </dataConfig>
4、复制solr-7.7.2\dist目录下的solr-dataimporthandler-7.7.2.jar和solr-dataimporthandler-extras-7.7.2.jar到solr-7.7.2/server/solr-webapp/webapp/WEB-INF/lib目录下
5、复制mysql驱动到solr-7.7.2/server/solr-webapp/webapp/WEB-INF/lib目录下
6、开始导入输入数据