Deleting Documents in Apache Solr manually

Multiple times, we need to remove the collection data manually, Like when it occupies a lot of space in the disk causing other services health problems.

To delete collection data manually, We can use the below command

curl -k --negotiate -u : "https://<Solr server hostname>:<Solr port>/solr/<collection name>/update?commit=true" -H "Content-Type: text/xml" --data-binary "<delete><query>evtTime:[* TO NOW-7DAYS]</query></delete>"

The above command will delete documents older than 7 days.

To Validate, We can run the below command to get the old and latest document and check the event time

# To check the oldest data:

curl -k --negotiate -u : "https://<Solr server host>:<Solr port>/solr/<collection name>/select?q=*%3A*&wt=json&ident=true&rows=1&sort=evtTime+asc"

# To check the latest data:

curl -k --negotiate -u : "https://<Solr server host>:<Solr port>/solr/<collection name>//select?q=*%3A*&wt=json&ident=true&rows=1&sort=evtTime+desc"

Please do share if you have any other ways.

Good Luck with your learning. Like the post if it is useful

Similar Posts