Home » Updating the Document Using XML in Apache Solr

Updating the Document Using XML in Apache Solr

by Online Tutorials Library

Updating the Document Using XML in Apache Solr

The XML file is given below that is used to update a filed in the existing document. You have to save this file with the name update.xml.

As we can see the file above that was written in XML to update is similar to which we used to add documents. But the difference between the XML and text document is that, we use the update attribute of the field in XML.

The above document will be used as an example, and we will try to update the fields of the document with the id 101.

Let’s take an example of an XML document that exists inside the bin directory of Apache Solr. Previously we are updating the index, which was saved in the core named my_core. Now, we will update using the post tool as given below:

When we compile and run the above command, we will get the following output.

/home/Hadoop/java/bin/java -classpath /home/Hadoop/Solr/dist/Solr-core  6.2.0.jar -Dauto = yes -Dc = my_core -Ddata = files   org.apache.Solr.util.SimplePostTool update.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 update.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.159  

Verifying the Document

You can now visit the homepage of the Apache Solr web interface and choose the core as my_core. We will now try to retrieve all the documents bypassing the query “:” in the text area q and execute it. You can now observe that the document is updated when executing.

Updating the Document Using XML in Apache Solr

Updating the Document Using Java (Client API)

Below is the Java program to add documents to the Apache Solr index. You can save this code in a file with the name UpdatingDocument.java.

Now, compile the above code by executing the command given below in the terminal.

You will get the following output when executing the above command.

Documents updated  

You may also like