SOLR environment Setup and full import of MySQL data

Source: Internet
Author: User
Tags solr

SOLR Document Preface

Because of the project to use SOLR, so spent more than a week to study the SOLR, the various problems I will not say, especially these two days in the study of timing Incremental index, in the mind do not know how many xxx in the Pentium, good, nonsense not to say, the following I have to share the results of research with you, In addition to SOLR is what, we still self-degree Niang bar, let me say I also said not clear.

Version

Solr

The latest version of SOLR is 5.3, but I'm not using the latest version, with 4.10.4.

Jdk

JDK version is jdk1.7.0_13, here is to say that the 4.10 version of SOLR needs more than 1.7 of the JDK, at first I used the 1.6 version of the JDK, but after the deployment has been an error, Baidu after the 1.7 version of the JDK is no problem.

Tomcat

Tomcat version is apache-tomcat-7.0.63, this doesn't matter, using Tomcat 6 is also possible.

Deployment

1. Download SOLR

Download from http://apache.dataguru.cn/lucene/solr/4.10.4/4.10.4 version of SOLR to this machine, put it anywhere.

2. Unzip

Unzip the downloaded solr4.10.4 compressed package to a local folder, the location is arbitrary, the extracted folder is as follows:

3. Deployment

(1) Copy example\ WebApps folder under the Solr.war file to Tomcat WebApps directory, start Tomcat decompression Solr.war, at this time Tomcat may error, but no tube, as long as the Solr.war extracted can (of course, can also be manually extracted), stop Tomcat, delete Solr.war, otherwise every boot will be re-decompressed.

(2) Go back to the WebApps directory of Tomcat and Notepad to open the Solr\web-inf\web.xml file. Add the following code as follows:

(3) as shown in the above code, the need to create a Solr_home folder, which can be placed on the drive to determine their own, mine is placed under the F disk.

(4) After creating the Solr_home folder, go back to the extracted SOLR 4.10.4 folder, copy all the contents below the EXAMPLE\SOLR folder to the Solr_home folder, and the Solr_home folder after the copy is complete as follows:

The dist and contrib folders are not required and can be used without consideration.

(5) Copy all the jar files under the Example\lib\ex folder to Webapps\solr\web-inf\lib.

(6) When you run HTTP://LOCALHOST:8080/SOLR, you will see a page that looks like this:

At this time, the environment of SOLR is completed (at this time only one CORE,SOLR is supported multicore, temporarily do not say, after the next), the following start data import:

(1) Open F:\SOLR_HOME\collection1\conf, under this folder can see Solrconfig.xml file, open the file, in <config></config> Add the following code as shown in the middle:

(2) The Data-config.xml file is introduced here, so the Data-config.xml file needs to be created in the same directory as the Solrconfig.xml, the file content is as follows:

Attention:

A.datasource label identifies the database in which the table to be indexed is located, configuration information you can see for yourself what you need, and I won't say much.

B.document the entity key in the tag, the document can have more than one entity tag, an entity corresponding to a table, if it is related to the table, then you need to nest the entity tag in the entity tag, this later, is now in a single sheet.

Name: Represents the current entity names, distinguishing multiple entity;

PK: The primary key of the table corresponding to the current entity;

Query: For full-scale indexing;

The next two for the incremental index is required, for the time being, say, after the incremental index, if it is only a full-scale index, then the following two is completely unnecessary;

C.field: The name of the field in the corresponding database, column corresponds to the database field name, the Name property can be set by itself, but corresponds to the field in the Schema.xml file;

TUSER Table Structure:

(3) Schema.xml configuration

A.schema.xml files and data-config.xml in the same directory, open the file, configured as follows:

Note the Field field configuration, The Name property corresponds to the name attribute in field in Data-config.xml, indexed is true to create an index on the field, and stored to TRUE indicates that the contents of the field are stored in the index file, that it is easy to return at query time, that there are very many fields, or only queries, but not You need to return the field of content, you can set stored to false;

B. Setting the index ID

Set the UniqueKey in the Schema.xml file as the primary key in the table, as follows:

(4) Elevate.xml

Elevate.xml file is also in the same directory as Solrconfig.xml, open the file, set the following:

The reason for this setting is because the ID in our table is of type int, and the ID is set to type int in Schema.xml, but SOLR's index requires a string type, and if you don't drop the two <doc> comment above, it will be an error.

(5) Importing JAR packages

The full-volume import configuration file is the top three, but importing data from a database requires three jar packages. One is the MySQL link database jar package (Mysql-connector-java-5.1.21.jar), the other two is SOLR do data import when needed, located in the decompression of SOLR 4.10.4 folder below the dist file under Solr-dataimporthandler-4.10.4.jar and Solr-dataimporthandler-extras-4.10.4.jar, put these three files into Tomcat \webapps\solr\web-inf\lib.

(6) Start Tomcat, access the LOCALHOST:8080/SOLR path, click on the following location:

The following menu appears, click on the DataImport menu to display the following page:

Click on the Execute button, click the Refresh button below, and then the right becomes as follows when the data import is complete:

You can query the index of the imported data creation by clicking on the Query menu and then clicking the Execute Query button on the page:

Numfound is the number of records in the database, and the data in my database is as follows:

You can see that there are only 12 data in my database, so the full index has been imported.

We'll write about this today, and we'll continue to write incremental imports and scheduled incremental imports the next time. I made a demo in the Baidu Cloud to share, need to download, put Solr_home on the F-plate, if you do not want to put in the F, you can change the Solr folder under the Web-inf in the Web. XML configuration can be.

Baidu Network disk address is: Http://pan.baidu.com/s/1sj9VlOp, the contents of the folder are as follows:

Solr folder directly in the WebApp under Tomcat, Solr_home, if you do not want to change the configuration can be placed in the F-packing directory, if placed on another disk, you need to modify SOLR in Web. XML configuration,

SQL file is needless to say, we all understand that the jar file is not used temporarily, do the regular incremental index when used, can not tube.

SOLR environment Setup and full import of 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.