Import data from a database into the SOLR index library

Source: Internet
Author: User
Tags solr

In the SOLR and Tomcat integration article, the index library I used is mycore, now take this as an example.

The first thing to prepare the jar package: Solr-dataimporthandler-4.8.1.jar, Solr-dataimporthandler-extras-4.8.1.jar and Mysql-connector-java-5.0.7-bin.jar These three packages to SOLR's Tomcat's webapps\solr\ Web-inf\lib under

In this folder conf configure two files, add a file. Configure Solrconfig.xml first.

Add a new node under the file.

<RequestHandlername= "/dataimport"class= "Org.apache.solr.handler.dataimport.DataImportHandler">        <LSTname= "Defaults">            <Strname= "config">Data-config.xml</Str>        </LST>    </RequestHandler>

Create the Data-config.xml in the same directory as the Solrconfig.xml.

Configuration:

<Dataconfig>    <DataSourcetype= "Jdbcdatasource"Driver= "Com.mysql.jdbc.Driver"URL= "Jdbc:mysql://localhost:3306/courseman"User= "root"Password= "MySQL" />    <Document>        <Entityname= "Student"Query= "SELECT * FROM Student">            <Fieldcolumn= "id"name= "id" />            <Fieldcolumn= "Name"name= "Name" />            <Fieldcolumn= "Gender"name= "Gender" />            <Fieldcolumn= "Major"name= "Major" />            <Fieldcolumn= "Grade"name= "Grade" />        </Entity>    </Document></Dataconfig>

Configuration of the Schemal.xml

<?XML version= "1.0"?><!--Licensed to the Apache software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License");  You are not a use of this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by applicable law O R agreed to writing, software distributed under the License are distributed on a "as is" BASIS, without warranties OR C Onditions of any KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -<Schemaname= "Example Core One"version= "1.1">    <FieldTypename= "string"class= "SOLR." Strfield "Sortmissinglast= "true"omitnorms= "true"/>    <FieldTypename= "Long"class= "SOLR." Trielongfield "Precisionstep= "0"Positionincrementgap= "0"/>    <FieldTypename= "int"class= "SOLR." Trieintfield "Precisionstep= "0"Positionincrementgap= "0"/>      <!-- General -  <Fieldname= "id"type= "int"indexed= "true"stored= "true"  />  <Fieldname= "Gender"type= "string"indexed= "true"stored= "true"   />   <Fieldname= "Name"type= "string"indexed= "true"stored= "true"   />   <Fieldname= "Major"type= "string"indexed= "true"stored= "true"   />  <Fieldname= "Grade"type= "string"indexed= "true"stored= "true"   />  <Fieldname= "_version_"type= "Long"indexed= "true"stored= "true"/>               <!--field to determine and enforce document uniqueness. - <UniqueKey>Id</UniqueKey> <!--field for the Queryparser-use if an explicit fieldname is absent - <Defaultsearchfield>Name</Defaultsearchfield> <!--solrqueryparser configuration:defaultoperator= "And|or" - <SolrqueryparserDefaultoperator= "OR"/></Schema>

The default file is not like this, slightly changed.

The type of field is defined according to the name of FieldType. The class is SOLR custom and cannot be changed.

Some of the others explain later.

You can now import data from your database into SOLR.

Click Execute to do it.

The data for the database came in.

The table for the database.

database table structure.

Import data from a database into the SOLR index library

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.