Solr, block updating of existing document

2019-05-05 23:34发布

问题:

When a document is sent to solr and such document already exists in the index (by its ID) then the new one replaces old one.

But I don't want to automatically replace documents. Just ignore and proceed to the next. How can I configure solr.

Of course I can query solr to check if it has the document already but it's bad for me since I do bulk updates and this will complicate the process and increase amount of request.

So are there any ways to configure solr to ignore duplicates?

回答1:

You can disable the automatic overwriting of documents with the same uniqueIndex specifying the attribute overwrite="false" within the add element while you send documents to the UpdateHandler. Have a look here.

<add overwrite="false">
    <doc>
        <field name="id">id</field>
    </doc>
</add>

Anyway this allows to have duplicate documents into solr, instead of skipping new documents with same id of existing ones. I don't think this is your desired behaviour.

I think you should write your own UpdateHandler or UpdateRequestProcessor or follow the suggestions you got from the solr user mailing list.