Using SOLR to build full-text retrieval for enterprises (iv) --- writing documents

Source: Internet
Author: User
Tags solr

Previous ArticleArticleThis article introduces how to define the SOLR schema. With the schema definition of data, let's take a look at how to write data. There are many ways to write document data to SOLR. You can use XML documents, JSON documents, and CSV documents. For these three methods, you can use curl in Linux to conveniently import data, for example, if you use an XML document, you can write it as follows:

Add XML document

Curl http: /localhost: 8983/SOLR/update? Commit = true-h "Content-Type: text/XML "-- Data-binary '<add> <Doc> <field name =" ID "> testdoc </field> </DOC> </Add>' 

Add JSON document

Curl http: // localhost: 8983/SOLR/update/JSON-H 'content-type: Application/json'-d' [{"ID": "testdoc1 ", "title": "test1" },{ "ID": "testdoc2", "title": "another test"}]' 

Of course, you can also use DIH (dataimporthandler, a solr processor, to import data in batches from other heterogeneous systems ).

If you want to import files in Windows, you can use the post. jar file under the example directory (example \ exampledocs ).ProgramAfter we build the SOLR environment, there is no file data in the system. Now we try to use post. jar program to import documents, you can use the command line (CMD Program), enter the SOLR document example directory (example \ exampledocs), and then enter Java-jar post. jar *. XML. After the input is complete, press enter to import the data to SOLR. Now we can check whether data has been imported on the statistics page of SOLR, for example:

 

We have imported 17 documents. To view the imported documents, enter "*: *" in the qeury string on the SOLR admin homepage (http: // localhost: 8983/SOLR/admin "*:*", click the search button to view the content of the first 10 documents we just imported to the system.

the preceding describes the import methods of several documents. DIH is relatively complicated. We will talk about other methods later. If you want to test the function, you can use them, if the formal production environment cannot do this, then we need some powerful clients to facilitate the introduction of SOLR functions into our own systems. We can access idea to use Ajax SOLR. For. net, I personally think solrnet is a good choice. I will also choose solrnet as the client for demonstration in subsequent articles. In the next article, I will talk about the use of solrnet.

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.