SOLR builds Solr5.2.1 services and imports data from MySQL

Source: Internet
Author: User
Tags apache solr solr

First, open SOLR services

1, first download solr-5.2.1.tgz package from SOLR official website, after decompression for solr-5.2.1.

2, read README.txt know through the bin/solr start command to open SOLR services, of course, you can add solr-5.2.1/bin environment variables inside. The service that opens at this point is placed under the jetty service, also can put under Tomcat, just feel that quite troublesome, also need to download a tomcat package again.

3, open the service, the default is to open the 8983 port, at this time you can use localhost:8983/solr/ to access, if not access, through the java-version Check your Java version to see if it is below java1.7, if below, please upgrade. In fact, inside the README.txt file, theinstructions for Building Apache SOLR is a line below the Source, which has been explicitly stated to download.

Second, import data from the MySQL database

1, create a core or collection, there are two ways to create
The first is to use the command line to see what README.txt knows
BIN/SOLR create-c Collection
The second use of access links to create
localhost:8983/solr/admin/cores?action=create&name=collection&instancedir=collection
The directory created by default is under SOLR-5.2.1/SERVER/SOLR

2. Modify the solr-5.2.1/server/solr/collection/conf/managed-schema file to schema.xml
Before entering the Conf folder a look, silly, incredibly no 4.6.1 inside the Schema.xml file, how do I set it? Later saw someone else's file said can set, I go to 4.6.1 copy one over, and then carefully see there is a managed-schema file, so try to open a look, see the following content:
This is the SOLR schema file. This file should is named "Schema.xml" and should is in the Conf directory under the SOLR home (i.e../solr/conf/schema.xml By default)

3, add filedin schema.xml , because my MySQL database only ID and name two fields, and name this filed in Schema.xml already exist, I just need to add ID on the line, as follows:

   <fields >        <field name= "id" type= "int" indexed="true" stored="true" required="true" />    </fields >    <uniquekey>Id</uniquekey>    <Defaultsearchfield>Name</Defaultsearchfield>

4, modify the configuration file for solrconfig.xml under solr-5.2.1/server/solr/collection/conf/, Configure the XML to add the database data as follows:

< RequestHandler  name  = "/dataimport"  Span class= "Hljs-attribute" >class  =;  <lst  name  = "defaults"   <str  n Ame  = "config" ;  data-config.xml</str ;  </lst  >
      </requesthandler ;   

5, create the solrconfig.xml file in the data-config.xml file, the internal main configuration of access to the database user name, password, and corresponding database fields, the file content is as follows:

<dataconfig>    <dataSource type= "jdbcdatasource"driver="Com.mysql.jdbc.Driver"  URL="Jdbc:mysql://localhost/database_name"user="UserName " Password="password"/>                    <document>        <entity name="Check_lawyer"query="SELECT ID, name from TableName" >                        <field column="id " name="id" />            <field column="Name " name="  name"/>        </entity>    </document></dataconfig>

NOTE: The above database_name is the database name you created, username is the database user name, password is the database password, tablename is your table name, column in the field area corresponds to the columns in the database, And name is the one shown in SOLR.

6. Copy the Solr-dataimporthandler-5.2.1.jar from the solr-5.2.1/dist/ folder to the solr-5.2.1/server/ In Solr-webapp/webapp/web-inf/lib , this Java package is used for importing data.

8, download a mysql-connector-java-5.1.35.zip compression package from the MySQL official website, extract a Mysql-connector-java-5.1.35-bin.jar package, Copy it to Solr-5.2.1/server/lib .

9, restart the service BIN/SOLR restart, in the browser input:localhost:8983/solr/dataimport?command=full-import to complete the full-volume data import, The original index is deleted each time the full data import is executed, and if you do not want to delete the original index, you can run the following command:localhost:8983/solr/dataimport?command=full-import&clean= False

10, if you do not use the method of step 9, you can also select the current core for collection, and then click DataImport, if the above configuration,command drop-down box will have a Full-import Select, select it, then click on the blue button below execute, wait a few minutes, after the refresh, the indexing completed appears. added/updated:1963 documents. Deleted 0 documents. (duration:01s) A similar field, indicating that the import of MySQL successfully, at this point can be queried

11,localhost:8983/solr/collection/select?q=%e6%98%a5&wt=json&indent=true input This link to query the results

Iii. Related errors:

1, the following, explained in Schema.xml repeatedly defined ID, block it off, restart the service
Collection:org.apache.solr.common.SolrException:org.apache.solr.common.SolrException:Could not load conf for core Collection: [schema.xml] Duplicate field definition for ' id ' [[id{type=string,properties=indexed,stored,omitnorms, Omittermfreqandpositions,sortmissinglast,required, required=true}]] and [[[Id{type=int,properties=indexed,stored , omitnorms,omittermfreqandpositions,required, required=true}]]. Schema file Is/users/user/lcg/web/solrserver/solr-5.2.1/server/solr/collection/conf/schema.xml

2, as follows, indicates that the name field is not defined in the Schema.xml file
Collection:org.apache.solr.common.SolrException:org.apache.solr.common.SolrException:Could not load conf for core Collection:default search field ' name ' not defined or not indexed. Schema file Is/users/user/lcg/web/solrserver/solr-5.2.1/server/solr/collection/conf/schema.xml

3, the <field name="name" type="string" indexed="true" stored="true"> back of a less/, should be <field name="name" type="string" indexed="true" stored="true"/> , after modification, restart the service
Collection:org.apache.solr.common.SolrException:org.apache.solr.common.SolrException:Could not load conf for core Collection:org.xml.sax.SAXParseException; Systemid:solrres:/schema.xml; linenumber:1028; Columnnumber:12; The end tag of the element type "field" must end with the ' > ' delimiter: Schema file Is/users/user/lcg/web/solrserver/solr-5.2.1/server/solr/collection/conf/schema.xml

Iv. References:

Http://www.csdn123.com/html/itweb/20130726/23894_23889_23891.htm

http://tbwuming.iteye.com/blog/1152333

http://ju.outofmemory.cn/entry/19792

http://blog.csdn.net/hbuxzy/article/details/9254071

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SOLR builds Solr5.2.1 services and imports data from MySQL

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.