[Jjzhu learn Java] solr4.9 sync mysql data

Source: Internet
Author: User
Tags solr import database


SOLR is a high performance, JAVA5 developed, Lucene-based full-text Search server. At the same time, it has been extended to provide a richer query language than Lucene, which is configurable, extensible, and optimized for query performance at the same time, and provides a good functional management interface, an excellent full-text search engine.

The ability to import data from a database into SOLR, and for millions data to respond to queries at high speed.

1. Installing the JDK

JDK version number requires more than 1.7

2. Installing SOLR

Download SOLR compression Pack and unzip the installation package. Go to the Solr_home\example folder, execute the command java–jar start.jar start SOLR



SOLR default port is 8983, Access HTTP://LOCALHOST:8983/SOLR, if you have such as the following interface, the start of success


3. Import and update data-related configuration

SOLR provides the ability to import database data into the SOLR Index Library (dataimport)

3.1. Download the database driver package

Download the MySQL driver package. And put it under the {%solr_home%}contrib\dataimporthandler\lib folder


3.2. Configuring solrconfig.xml3.2.1, referencing related libraries

The solrconfig.xml includes most of the parameters used to configure the behavior of itself, which is scoped to the current core. Location in the Files folder the file is located under {%solr_home%} example\solr\collection1\conf.

The data import needs to reference the MySQL driver package and the package required by the DataImport.

Include in the file such as the following:

<libdir= ". /.. /.. /contrib/dataimporthandler/lib "regex=". *\.jar "/>

<lib dir= ". /.. /.. /dist/"regex=" Solr-dataimporthandler-\d.*\.jar "/>

3.2.2, Configuration RequestHandler

Add for example the following configuration in Solrconfig.xml:

<requesthandlername= "/dataimport" class= "Org.apache.solr.handler.dataimport.DataImportHandler" >

<lst name= "Defaults" >

<str name= "config" >data-config.xml</str>

</lst>

</requestHandler>


3.3, Configuration Schema.xml

Schema.xml has the flexibility to configure different types of fields in the same location as the Solrconfig.xml peers.

Importing data requires configuring a type that is consistent with the fields in the database, in the configuration file


3.3. Configure the data source

Under the Solrconfig.xml Sibling folder ({%solr_home%}example\solr\collection1\con), establish a data profile data-config.xml with the same name as the configuration in 3.2.2,


and add for example the following content

<dataConfig>

<!--driver: Database driver name

URL: Database path

User: Database Users

Password: Database password

BatchSize: Prevents memory overflow during import of data

-

<datasource type= "Jdbcdatasource"

Driver= "Com.mysql.jdbc.Driver"

Url= "Jdbc:mysql://localhost/exercise"

User= "Root"

Password= ""

Batchsize= "-1"/>

<document>

<!--the tables to be imported, you can configure multiple

and query the fields to be indexed

-

<entity name= "CustomerInfo" query= "Selectcustomerid,customername,pid,telephone from CustomerInfo" >

<field column= "CustomerID" name= "id"/>

<field column= "CustomerID" name= "CustomerID"/>

<field column= "CustomerName" name= "CustomerName"/>

<field column= "pid" name= "pid"/>

<field column= "Telephone" name= "Telephone"/>

</entity>

</document>

</dataConfig>

4. Import data

Access to the SOLR interface



Command Select Full-import,entity Select the table to import, then click Execute to import the data


After completion, you will be prompted to complete the index.

Then, in the query interface can enter the relevant query criteria for querying


[Jjzhu learn Java] solr4.9 sync mysql data

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.