Apache Solr Adding Documents (XML) - Apache Solr

How to add data in Apache Solr using XML documents?

The chapter demonstrates on how to add data in Apache Solr index using XML document format.

Sample Data

For instance, the following data need to be added to Solr index using XML file format.

Student ID
First Name
Last Name
Phone
City
001
Rajiv
Reddy
9848022337
Hyderabad
002
Siddharth
Bhattacharya
9848022338
Kolkata
003
Rajesh
Khanna
9848022339
Delhi
004
Preethi
Agarwal
9848022330
Pune
005
Trupthi
Mohanty
9848022336
Bhubaneshwar
006
Archana
Mishra
9848022335
Chennai

Adding Documents Using XML

An XML document needs to be prepared for adding the data into Solr index as shown below. Save the document in a file as sample.xml.

Three important tags <add> </add>, <doc></doc>, and < field >< /field > are there in the XML file written to add data to index.

  • add − This is the root tag for adding documents to the index. It contains one or more documents that are to be added.
  • doc − The documents we add should be wrapped within the <doc></doc> tags. This document contains the data in the form of fields.
  • field − The field tag holds the name and value of the fields of the document.

After the document is prepared, the document is added to the index using different methods discussed in earlier chapters.

If the XML file exists in the bin directory of Solr and it is to be indexed in the core named my_core, add it to Solr index using the post tool as follows −

On executing the above command, the following output appears.

Verification

To verify, in the home page of Apache Solr web interface, select the core my_core. All the documents can be retrieved by passing the query “:” in the text area q and execute the query. On execution of the query, it is observed that the desired data is added to the Solr index.

Solr Index

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache Solr Topics