SOLR Database Import
1. Create a table T_SOLR in MySQL and insert the test data.
2, put E:\Solr\solr-4.10.4\example\example-DIH\solr\db\conf under the admin-extra.html, Admin-extra.menu-bottom.html,admin-extra.menu-top.html three files are also copied to the Conf.
Open the E:\Solr\solrHome\mycore\conf path under the
Solrconfig.xml file, add the following node:
<requesthandlername= "/dataimport" class= "Org.apache.solr.handler.dataimport.DataImportHandler" > <lstname= "Defaults" > <strname= "config" >data-config.xml</str> </lst> </requestHandler> |
3, create a new Data-config.xml file, and solrconfig.xml the same directory. The contents are:
<dataConfig> <datasource type= "Jdbcdatasource" Driver= "Com.mysql.jdbc.Driver" Url= "Jdbc:mysql://localhost/test" User= "Root" password= "Giser"/> <document> <entity name= "T_SOLR" transformer= "Dateformattransformer" query= "SELECT ID, subject, content, last_update_time from T_SOLR WHERE ID >= ${dataimporter.request.id}" > <field column= ' last_update_time ' datetimeformat= ' yyyy-mm-dd HH:mm:ss '/> </entity> </document> </dataConfig> |
Note: A ${dataimporter.request.id} is used here, which is the parameter, which is used when the data is imported, and the datum is read by this condition.
4. Copy the extracted SOLR jar package (E:\Solr\solr-4.10.4\dist) Solr-dataimporthandler-4.10.0.jar and Solr-dataimporthandler-extras-4.10.0.jar to the Web-inf\lib directory of the Tomcat SOLR WebApp (E:\ Solr\apache-tomcat-7.0.65\webapps\solr\web-inf\lib).
Of course, it also includes the JDBC jar package for MySQL: Mysql-connector-java-5.1.7-bin.jar
(Another way is to add the Lib node to the Solrconfig.xml and then put the jar package under solrhome so that the jar package is not added to the Web-inf\lib)
5. Open the Schema.xml under E:\Solr\solrHome\mycore\conf path with Notepad, and add the following in the Solrhome folder:
<!-type corresponds to <fieldtype name= "string" class= "SOLR. Strfield "sortmissinglast=" true "omitnorms=" true "/> <fieldtype name= "Long" class= "SOLR. Trielongfield "precisionstep=" 0 "positionincrementgap=" 0 "/> <field name= "Subject" type= "string" indexed= "true" stored= "true"/> <field name= "Content" type= "string" indexed= "true" stored= "true"/> <defaultSearchField>subject</defaultSearchField> |
6. Open SOLR, query data
Direct access to:http://localhost:8080/solr/mycore/dataimport?command=full-import&clean=true&commit=true& via address Wt=json&indent=true&entity=t_solr&verbose=false&optimize=false&debug=false&id=1
Results:
After the configuration, we only need to use this URL address, we can continue to import data to index.
To generate an index from DataImport:
Query Result:
Summarize:
Encountered issue 1:
MySQL java.sql.SQLException:Unknown system variable ' language& #03 One: The problem description: MySQL Test connection consistent error: Unknown system variable ' language ' unknown systems variable language Two: MySQL version 5.6 with the connection jar Mysql-connector-java-5.1.36.jar Three: Find the problem, Mysql-connector-java-5.1.36.jar version is too high, replaced by Mysql-connector-java-5.1.24.jar Problem Solving! |
Encountered issue 2:
Put the solr-6.0\solr-6.0.0\example\example-dih\solr\db\conf under the admin-extra.html, Admin-extra.menu-bottom.html,admin-extra.menu-top.html three files are also copied to the Conf.
SOLR Database Import