Solr XML Document Delete
We can use the delete command to delete the documents which are stored in Apache Solr index. We can delete the
documents based on the document ID by specifying them in the
We have already added the moneydata.xml XML document in Apache Solr index in the Document Addition section which has the following records.
USD
One Dollar
Bank of America
boa
currency
Coins and notes
1,USD
true
EUR
One Euro
European Union
eu
currency
Coins and notes
1,EUR
true
GBP
One British Pound
U.K.
uk
currency
Coins and notes
1,GBP
true
NOK
One Krone
Bank of Norway
nor
currency
Coins and notes
1,NOK
true
Now we will see how to delete indexed records based on the ID or field name of the document in the following section.
Deleting Documents from Solr Index based on Document ID
We can delete the documents from Apache Solr Index using the ID of the document.
In the below example we will delete the Solr index document for those records which are having ID=USD. For that, we will create an XML file with the name deleteID_moneydata.xml under the Solr Home /bin directory and put the following records in that file.
USD
Now we will use the deleteID_moneydata.xml XML file to delete the records that have the ID=USD. Please note that we will use the Solr_sample_core core to perform this operation. The Solr_sample_core was created during the Core creation & deletion section of the tutorial.
Command:
cloudduggu@ubuntu:~/hadoop/solr-8.8.1/bin$ ./post -c Solr_sample_core deleteID_moneydata.xmlOutput:
Once the command is executed successfully, we will see the below output.
We can verify the deletion of the document from the Apache Solr Web interface, we can click on execute query button and see that the document with ID=USD has been deleted from the Solr index.
Deleting Documents from Solr Index based on a Field
We can delete a document from the Solr index based on a field value. For example, if we want to delete a document that has a file name like Emp_Work_Location: Deoria.
The field name should be specified in the
Emp_Work_Location:Deoria
Now, let us run the Post command to delete the document with matching field names from the Solr index.
Command:
cloudduggu@ubuntu:~/hadoop/solr-8.8.1/bin$ ./post -c Solr_sample_core deletefield_moneydata.xmlOutput:
The below output is generated once the command is completed successfully.
Deleting All Documents from Solr Index
We can delete all documents from the Apache Solr Index bypassing the *:* in the delete tag. To perform this operation we have created an XML file name deleteall.xml and we will pass it to the Post command as mentioned below.
Command:
cloudduggu@ubuntu:~/hadoop/solr-8.8.1/bin$ ./post -c Solr_sample_core deleteall.xmlOutput:
The following message we can see after the command execution.
We can verify it from the Apache Solr Web interface by Querying. Click on the Query option and leave everything default after that click on the Execute Query button. We will see that all documents which were stored under the Solr Core Solr_sample_core are deleted now.