Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
Question:how to Deleting Data using solr?
You can delete data by POSTing a delete command to the update URL and specifying the value of the document's unique key field, or a query that matches multiple documents (be careful with that one!). Since these commands are smaller, we will specify them right on the command line rather than reference an XML file.
Execute the following command to delete a specific document
java -Ddata=args -Dcommit=false -jar post.jar "
Because we have specified "commit=false", a search for id:SP2514N we still find the document we have deleted. Since the example configuration uses Solr's "autoCommit" feature Solr will still automatically persist this change to the index, but it will not affect search results until an "openSearcher" commit is explicitly executed.
Using the statistics page for the updateHandler you can observe this delete propogate to disk by watching the deletesById value drop to 0 as the cumulative_deletesById and autocommit values increase.
Here is an example of using delete-by-query to delete anything with DDR in the name:
java -Dcommit=false -Ddata=args -jar post.jar "
You can force a new searcher to be opened to reflect these changes by sending a commit command to Solr (which post.jar does for you by default):
java -jar post.jar
Now re-execute the previous search and verify that no matching documents are found. You can also revisit the statistics page and observe the changes to both the number of commits in the updateHandler and the numDocs in the searcher.
Commits that open a new searcher can be expensive operations so it's best to make many changes to an index in a batch and then send the commit command at the end. There is also an optimize command that does the same things as commit, but also forces all index segments to be merged into a single segment -- this can be very resource intsenive, but may be worthwhile for improving search speed if your index changes very infrequently.
All of the update commands can be specified using either XML or JSON.
To continue with the tutorial, re-add any documents you may have deleted by going to the exampledocs directory and executing
java -jar post.jar *.xml
Sep 13, 2013
Sep 12, 2013
to add a comment.
Related Hot Questions
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please