SOLR simple integration with MySQL

Source: Internet
Author: User
Tags solr

The integration of SOLR and MySQL databases enables the creation of full-scale indexes and incremental indexes.
The rationale is simple: Register SOLR's Dataimporthandler in the SOLR project and configure the MySQL data source and the data query SQL statement. When we use the SOLR background control page or directly access an address (given later), SOLR invokes Dataimporthandler, connects to the database, queries the data based on the SQL statement, and creates the index.

Example SOLR version: solr4.3.1
Contract the installation directory of SOLR, such as E:\environment\solr-4.3.1 for Solr-home.


1. Copy the jar package
Copy the jar containing the Dataimporthandler and the MySQL database driver package to the Solr-home/dist directory. By default, the two jar packages required for Dataimporthandler already exist in this directory. The name of the jar package for the SOLR version is: Solr-dataimporthandler-4.3.1.jar, Solr-dataimporthandler-extras-4.3.1.jar

2. Modify the Solr-home\example\solr\collection1\conf\solrconfig.xml file
A. Add the required jar-Package reference configuration:

HTML code
    1. <Lib dir=". /.. /.. /dist/" regex="solr-dataimporthandler-.*\.jar " />
    2. <Lib dir=". /.. /.. /dist/" regex="mysql-connector-java-.*\.jar " />



B. Add Resulthandler Configuration

HTML code
  1. <requesthandler name="/dataimport"
  2. class="Org.apache.solr.handler.dataimport.DataImportHandler">
  3. <lst name="Defaults">
  4. <str name="config">data-config.xml</str>
  5. </lst>
  6. </requesthandler>



3. Create the Data-config.xml file in the Solrconfig.xml's sibling directory, configure the database connection and SOLR's correspondence with MySQL data and query statements.

HTML code
  1. <dataconfig>
  2. <dataSource type="Jdbcdatasource" driver="Com.mysql.jdbc.Driver "
  3. url="Jdbc:mysql://127.0.0.1/dbname" user="root" password="root"/>
  4. <document name="Search_object">
  5. <entity name="talent"
  6. query= "SELECT ID, Gender, QQ, MSN, Anualsalary, UpdateTime, Adduserid
  7. From talent ">
  8. <field column= "anualsalary" name="Salary"/>
  9. <field column="Adduserid" name= "userId"/>
  10. <!--Talent names-->
  11. <entity name="Talent_name" query="Select value from Talentname where talentid= ' ${ Talent.id} ' ">
  12. <field column="value" name="name"/>
  13. </Entity>
  14. </Entity>
  15. </Document>
  16. </dataconfig>



4. Restart SOLR.
Bulk Import (Full-import):
Http://
Incremental import (Delta-import):
Http://
Import State Query (status):
Http://
Reload configuration file (Reload-config):
Http://
Terminate import (Abort):
Http://

SOLR simple integration with MySQL

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.