solr6.6.2 Learning record Three: Importing data from SQL Server database (full-scale import)

Source: Internet
Author: User
Tags solr

1. Configuration Preparation

The premise has been configured with SOLR, and a new core has been created; (Mine is: D:\solr_home\core_demo)

SQL Server database, with database: DEMO_SOLR, single table (Demo_user) as an example.

2, modify the Sorlconfig.xml

Sorlconfig.xml localisation: D:\solr_home\core_demo\conf;

In Soreconfig.xml's <requesthandler name= "/select" class= "SOLR. Searchhandler "> Add the following code:

  Note: You need to confirm that there are no other dataimport in the file, if there is a direct replacement.

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

3. Create a Data-config.xml file

For detailed configuration Please refer to: http://blog.csdn.net/boolbo/article/details/50352331

Official wiki:https://cwiki.apache.org/confluence/display/solr/

Create the Data-config.xml file in the directory where the Sorlconfig.xml is located, and then configure the database-related properties in this file. For example:

<?xml version= "1.0" encoding= "UTF-8"?> <dataConfig> <datasource name= "DataSource" type= " Jdbcdatasource "Driver= "Net.sourceforge.jtds.jdbc.Driver"URL= "Jdbc:jtds:sqlserver://127.0.0.1:1433/demo_solr;uselobs=false"User= "SA"Password= "123456"/> <document> <entity name= "Demo_user" datasource= "DataSource" pk= "id"Query= "SELECT * from Demo_user" > <field column= ' id ' name= ' id '/> <field column= ' name ' name= ' n            Ame '/> <field column= ' address ' name= ' address '/> <field column= ' age ' name= ' age '/>  <field column= ' create_time ' name= ' createtime ' datetimeformat= ' yyyy-mm-dd HH:mm:ss '/> <field column= ' update_time ' name= ' updatetime ' datetimeformat= ' yyyy-mm-dd HH:mm:ss '/> </entity> </document ></dataconfig

4, Configuration Managed-schema.xml

6.6.2 version directly modified managed-schema.xml, such as my managed-schema.xml file all the following:

<?xml version= "1.0" encoding= "UTF-8"? ><schema name= "Example" version= "1.6" > <field name= "id" type= "str ing "indexed=" true "stored=" false "/> <field name=" name "type=" string "indexed=" true "stored=" true "/> <fiel D name= "age" type= "int" indexed= "true" stored= "true"/> <field name= "Address" type= "string" indexed= "true" stored= "True"/> <field name= "createtime" type= "date" indexed= "true" stored= "true"/> <field name= "Cupdatetime" Typ    E= "Date" indexed= "true" stored= "true"/> <field name= "_version_" type= "Long" indexed= "false" stored= "false"/> <field name= "Text" type= "string" indexed= "true" stored= "false" multivalued= "true"/> <field name= "_root_" Typ  E= "string" indexed= "true" stored= "false" docvalues= "false"/> <uniqueKey>id</uniqueKey> <fieldtype Name= "string"class= "SOLR." Strfield "sortmissinglast=" true "/> <fieldtype name=" int "class= "SOLR." Trieintfield "docvalues=" true "precisionstep=" 0 "positionincrementgap=" 0 "/> <fieldtype name=" Long "class= "SOLR." Trielongfield "docvalues=" true "precisionstep=" 0 "positionincrementgap=" 0 "/> <fieldtype name=" Date "class= "SOLR." Triedatefield "docvalues=" true "precisionstep=" 0 "positionincrementgap=" 0 "/></schema>

5. Copy jar

(1) Copy solr-6.6.2\dist path under Solr-dataimporthandler-6.6.2.jar, Solr-dataimporthandler-extras-6.6.2.jar to Tomcat Under the Webapps\solr\web-inf\lib directory

(2) Copy jtds-1.2.4.jar (SQL Server database connection jar package) to Webapps\solr\web-inf\lib directory under Tomcat

You do not need to modify any of the configuration files, continue with the following steps

6. Modify the Jar configuration path

Continue editing the Solrconfig.xml, find the lib tag, modify the path of the jar, do not need to add any jar, paste the following my local modified path:

 <lib dir= "D:\java\componets\solr-6.6.2/contrib/extraction/lib" regex= "*\.jar"/> <lib dir= "D:\java\ componets\solr-6.6.2/dist/"regex=" Solr-cell-\d.*\.jar "/> <lib dir=" d:\java\componets\solr-6.6.2/contrib/ clustering/lib/"regex=". *\.jar "/> <lib dir=" d:\java\componets\solr-6.6.2/dist/"regex=" solr-clustering-\d.* \.jar "/> <lib dir=" d:\java\componets\solr-6.6.2/contrib/langid/lib/"regex=". *\.jar "/> <lib dir=" D:\ java\componets\solr-6.6.2/dist/"regex=" Solr-langid-\d.*\.jar "/> <lib dir=" d:\java\componets\solr-6.6.2/ contrib/ltr/lib/"regex=". *\.jar "/> <lib dir=" d:\java\componets\solr-6.6.2/dist/"regex=" Solr-ltr-\d.*\.jar " /> <lib dir= "D:\java\componets\solr-6.6.2/contrib/velocity/lib" regex= ". *\.jar"/> <lib dir= "D:\java\ componets\solr-6.6.2/dist/"regex=" Solr-velocity-\d.*\.jar "/> 

7. Restart Tomcat, visit: Http://127.0.0.1:8080/solr/index.html#/core_demo/dataimport//dataimport, such as:

(Full-import full-volume import, delta-import-incremental import), select Full-import, click Execute to import.

8. Click on the left to query the imported data to complete.

solr6.6.2 Learning record Three: Importing data from SQL Server database (full-scale import)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.