Javatpoint Logo
Javatpoint Logo

Apache Solr - Adding Document

In the Apache Solr Core, we saw the way to add data into Solr, which is in the file format of JSON and .CSV. This page will illustrate how to add data into Apache Solr index using XML file format.

Sample File

Let's the following data to be added to the Solr index using the XML file format.

Student ID First Name Phone City
001 Olivia +148022337 California
002 Emma +148022338 Hawaii
003 Sophia +148022339 Florida
004 Emily +148022330 Texas
005 Harper +148022336 Kansas
006 Scarlett +148022335 Kentucky

Adding Documents Using XML

For the addition of the above data into the Solr index, we should prepare an XML document, as given below. Save the following document in a file with the name sample.xml.

As we can see, the XML file created to add data to index file contains the given three important tags named as, <add> text </add>, <doc> text </doc>, and < field > text < /field >.

  • < add > - The add tag is the root tag for addition of the documents for indexing. It acquires one or more documents which will be added to the index.
  • < doc > - The data we added should be wrapped under the <doc> text here </doc> tags. The given document contains the data in the form of fields.
  • < field > - This tag holds the name and value of the fields of the data we added.

After creating the document, we can add the created document to the index with the means discussed in the indexing.

Suppose the XML file exists in the Solr's bin directory and it is to be indexed in the my_core file, then we can add it to index fo Solr using the post tool as given below -

When we run the above given command, we will get the below result.

Verification

Go to the homepage of Apache Solr web UI and choose the my_core file. Try to get all the documents bypassing the query ":" inside the text area q and run the query. After executing, we can observe that the desired data is added to the Solr index.

Apache Solr - Adding Document
Next Topic#




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA