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.