Apache Solr - Adding Document
Let's the following data to be added to the Solr index using the XML file format.
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 >.
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.
/home/Hadoop/java/bin/java -classpath /home/Hadoop/Solr/dist/Solr- Core8.2.0.jar -Dauto = yes -Dc = my_core -Ddata = files org.apache.Solr.util.SimplePostTool sample.xml SimplePostTool version 5.0.0 Posting files to [base] url http://localhost:8983/Solr/my_core/update... Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx, xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log POSTing file sample.xml (application/xml) to [base] 1 files indexed. COMMITting Solr index changes to http://localhost:8983/Solr/my_core/update... Time spent: 0:00:00.201
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.