Solr (bulk import data)

Solr (bulk import data)


Preparation: database table creation

Step 1: Guide the package

Import solr-dataimporthandler-4.10.3.jar and solr-dataimporthandler-extras-4.10.3.jar from solr-4.10.3 -> dist into the lib directory of the index library. If there is no lib directory, create a lib directory by yourself.

Note: You also need to connect the jar package of the mysql database




Step 2. In the core configuration file of collection1, add a request handler

Configuration:

   <requestHandler name="/dataimport"
		class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
     </lst>
  </requestHandler>


Step 3. Create a new data-config.xml file in the conf directory. This file is used to connect to the database and to complete the mapping of database fields and domains during import, and write the following configuration in it:

<?xml version="1.0" encoding="UTF-8" ?>  
<dataConfig>   
<dataSource type="JdbcDataSource"   
		  driver="com.mysql.jdbc.Driver"   
		  url="jdbc:mysql://localhost:3306/lucene"   
		  user="root"   
		  password="123456"/>   
<document>   
	<entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">
		 <field column="pid" name="id"/>
		 <field column="name" name="product_name"/>
		 <field column="catalog_name" name="product_catalog_name"/>
		 <field column="price" name="product_price"/>
		 <field column="description" name="product_description"/>
		 <field column="picture" name="product_picture"/>
	</entity>   
</document>   

</dataConfig>


Note: The name value in the field tag in data-config.xml must exist in schema.xml. Otherwise an error will occur.

Expansion: Add field configuration in schema.xml

<!--product-->
   <field name="product_name" type="text_ik" indexed="true" stored="true"/>
   <field name="product_price"  type="float" indexed="true" stored="true"/>
   <field name="product_description" type="text_ik" indexed="true" stored="false" />
   <field name="product_picture" type="string" indexed="false" stored="true" />
   <field name="product_catalog_name" type="string" indexed="true" stored="true" />

   <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
   <copyField source="product_name" dest="product_keywords"/>
   <copyField source="product_description" dest="product_keywords"/>


interface:



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325993921&siteId=291194637