Solr XML Document Addition

In this tutorial, we will go through the XML data addition in Apache Solr. In the previous section, we already covered the JSON and CSV format. The XML file format has the three important tags which are added, docs, and the fields. The add is the root tag that contains one or more docs tags to store one or many documents, the docs tags contain one or more field tags, and the last one is field tags which contains the actual data.

Let us see the below example to add a sample XML file of moneydata.xml file to Apache Solr index.

The moneydata.xml file contains the following records and we have created it in the /bin directory of Apache Solr home. The location of the file in our case is cloudduggu@ubuntu:~/hadoop/solr-8.8.1/bin$.

<add> <doc> <field name="id">USD</field> <field name="name">One Dollar</field> <field name="manu">Bank of America</field> <field name="manu_id_s">boa</field> <field name="cat">currency</field> <field name="features">Coins and notes</field> <field name="price_c">1,USD</field> <field name="inStock">true</field> </doc> <doc> <field name="id">EUR</field> <field name="name">One Euro</field> <field name="manu">European Union</field> <field name="manu_id_s">eu</field> <field name="cat">currency</field> <field name="features">Coins and notes</field> <field name="price_c">1,EUR</field> <field name="inStock">true</field> </doc> <doc> <field name="id">GBP</field> <field name="name">One British Pound</field> <field name="manu">U.K.</field> <field name="manu_id_s">uk</field> <field name="cat">currency</field> <field name="features">Coins and notes</field> <field name="price_c">1,GBP</field> <field name="inStock">true</field> </doc> <doc> <field name="id">NOK</field> <field name="name">One Krone</field> <field name="manu">Bank of Norway</field> <field name="manu_id_s">nor</field> <field name="cat">currency</field> <field name="features">Coins and notes</field> <field name="price_c">1,NOK</field> <field name="inStock">true</field> </doc> </add>

solr xml data addition cloudduggu

Now let us add the XML file moneydata.xml in the core Solr_sample_core using the Solr Post command as mentioned below.


cloudduggu@ubuntu:~/hadoop/solr-8.8.1/bin$ ./post -c Solr_sample_core moneydata.xml


After successful execution of the command, we will see the below output.

solr xml indexing post command cloudduggu

We can verify the document addition from the Apache Solr web interface as well. Just click on the Query tab and increase the page to 30 and click on the Execute Query button.

solr xml file output verification cloudduggu

We can see here the document has been added to the Solr index.

solr xml file output cloudduggu