SOLR environment Setup and full import of MySQL data

Source: Internet
Author: User
Tags solr

SolrDocumentObjective

Because SOLRwas used in the project, it took more than a week to study SOLR, and I did not say any of the questions, especially in the two days when I was studying timing incremental indexing, I didn't know how many XXX in the Pentium, okay, nonsense not much to say, the following I have to share the results of research, and also for SOLR is what, everybody still self-degree niang, let me say I also say 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 to say is 4.10 version of SOLR need to 1.7 above the JDK , I started with the 1.6 version of the JDK, but after the deployment has been an error , Baidu replaced by the 1.7 version of the JDK there's 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 4.10.4 version of SOLR from http://apache.dataguru.cn/lucene/solr/4.10.4/ to this machine, you can put it in one place.

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 the Solr.war file under the Example\webapps folder into the WebApps directory of Tomcat and start the Tomcat decompression Solr.war, at this time Tomcat may error, but no tube, as long as the Solr.war extracted out can (of course, can also be manually extracted), stop Tomcat, Remove Solr.war, or re-unzip every time you start.

(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 and copy the example\solr All the contents below the folder are in the solr_home folder, and the Solr_home folder after the copy is complete is 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 was completed (at this time only one core,solr support multicore , let's not say it for the time being, and then start with the data import:

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

(2) The data-config.xml file is introduced here , so you need to create the data-config.xml in the same directory as the solrconfig.xml file, the contents of the file are 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.

The entity key in the b.document tag says that There can be multiple entity tags in the document , a entity corresponds to a table, if it is an association table, then you need to nest the entity tag in the entity tag , this later, For now, it's 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 field name in the corresponding database,column corresponds to the database field name,thename property can be set by itself, but with field correspondence 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:

AttentionFieldthe configuration of the field,nameproperty to andData-config.xmlinFieldin thenameproperty corresponds to theindexedto betrueindicates that an index is created on this field.storedto betrueindicates that the contents of the field are stored in the index file, that it is easy to return when queried, that for fields with a particularly great content, or that only queries are required, but no fields are required to return content, you can setstoredto befalse;

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 in Schema.xml is also of type int, but SOLR 's index requires a string type if it does not put the above two <doc> comment out, then the error will be.

(5) importing jar Packages

The full-volume import configuration file is the top three, but importing data from a database requires threeJarpackage, one isMySQLof a linked databaseJarPackage (Mysql-connector-java-5.1.21.jar), the other two areSOLRWhen doing data import, it is necessary to extract theSOLR 4.10.4folder below theDistfile below theSolr-dataimporthandler-4.10.4.jarand theSolr-dataimporthandler-extras-4.10.4.jar, put these three files intoTomcat\webapps\solr\web-inf\libNext.

(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 a few 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 can, if you do not want to put in F You can change it for yourself. SOLR folder below the Web-inf in the Web. XML can be configured in the.

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

SOLR folder is placed directly under Tomcat WebApp ,solr_home, if you do not want to change the configuration can be placed in F Packing directory, if placed on another disk, you need to modify the configuration in solr in Web. Xml ,

SQL file is needless to say, we all understand that thejar 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.