Delete solr docs without commiting

Viewed 21

For my usecase, I will be deleting all solr docs everyday and indexing new solr docs right after it:

Delete:

conf = {
        "set-property": [
            {"requestDispatcher.requestParsers.enableRemoteStreaming": True},
            {"requestDispatcher.requestParsers.enableStreamBody": True},
        ]
    }
resp = requests.post(f"http://{SOLR_HOST}:{SOLR_PORT}/solr/product_{country}/config", json=conf)
     
resp = requests.get(
        f"http://{SOLR_HOST}:{SOLR_PORT}/solr/product_{country}/update"
        + "?stream.body=<delete><query>*:*</query></delete>"
    )

Insert: pySolr.solr.add_objects(..., commit=true, softCommit=true)

This seems to work fine. However, if I add a breakpoint between insert and delete, I notice that my solr core is empty (0 docs). Is there any way I can maintain the old solr docs until the insert command runs succesfully?

2 Answers

You can create a new core with different name and then once it completed then delete the old one.

After deleting the old one you can rename the new one with required name.

Here is the api for renaming the core.

admin/cores?action=RENAME&core=core-name&other=other-core-name

core : The name of the Solr core to be renamed.

other : The new name for the Solr core.

Note : You can also check if SWAP works in your case. SWAP atomically swaps the names used to access two existing Solr cores

You can refer the documentation here

If your use case is just to delete all the records and to re-index all of them, assuming that you have 'id' field custom generated instead of auto-generation and the no of records that would be re-indexed will be equal to or greater than the existing records in collection and while re-indexing all the records that already exists are re-indexed. Then you don't have to delete and then re-index. Indexing a existing document which has the same id replaces the existing document. Thus eliminating the step to delete the document.

Related