Solr4.6 import data using csv files

Source: Internet
Author: User
Tags solr

After solr4.6 is installed, I tried to import data to collection1 in batches using csv files.

First, write the csvfile (book.csv. My path is: E:/book.csv. And pay attention to the file encoding. My encoding is GB2312. It will be used for later uploads. If it is wrong, Chinese characters will be garbled.

Id; title; content
16. "New Year's Eve"; "a chairman is on stage and will not have a holiday on New Year's Eve. "
17. "Diaoyu Islands"; "Diaoyu Islands belong to China, while cangjingkong belongs to the world"

Then modify schema. xml. Clear all the defined fields in fields, but keep the "_ version _", and "_ root _" elements. The fields are defined as follows:

<Field name = "id" type = "string" stored = "true" indexed = "true"/>
<Field name = "title" type = "string" stored = "true" indexed = "true"/>
<Field name = "content" type = "string" stored = "true" indexed = "true"/>

You also need to modify solrconfig. xml.

Take the following section:

<RequestHandler name = "/update/csv" class = "solr. CSVRequestHandler">
<Lst name = "defaults">
<Str name = "stream. contentType"> application/csv </str>
</Lst>
</RequestHandler>

Replace:

<RequestHandler name = "/update/csv" class = "solr. CSVRequestHandler" startup = "lazy">
<Lst name = "defaults">
<Str name = "separator" >;</str>
<Str name = "header"> true </str>
<Str name = "encapsulator"> "</str>
</Lst>
</RequestHandler>

The separator field indicates that each field of data in each row is separated by a semicolon.

After all the modifications, restart tomcat. In windows, execute the following http request in the address bar of the browser:

Http: // localhost: 8080/solr/update/csv? Commit = true & stream. file = E:/book.csv & stream. contentType = text/plain;
Charset = GB2312

Note that commit = true must exist, otherwise data insertion will not succeed. E:/book.csv. This is the absolute path of the file .; Charset = GB2312: This is the file encoding method of my csv file. Make sure that this is clear; otherwise, Chinese characters are garbled.

After the execution, view the result:

Solr details: click here
Solr: click here

Solr3.6.1 build an environment in Tomcat6

Tomcat-based Solr3.5 cluster deployment

Load Balancing for Solr clusters using Nginx on Linux

Install and use Solr in Linux

Deploy Solr 4 on Ubuntu 12.04 LTS through Tomcat

Solr implements Low Level query parsing (QParser)

Build a search Server Based on Solr 3.5

Solr 3.5 development and application tutorial PDF

Solr 4.0 deployment instance tutorial

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.