The goal is to properly delete the old document, then add the new document, whenever a document id changes. I don't think it currently works in 5: no code seems to exist to handle this specific case. The easiest solution would probably be to require the integration (ISPN, ORM) to call delete() then add() on the PojoWorker. Note that:
- The old and new documents will be in the same index, but they might be in a different shard.
- The client might not be able to provide the full old entity for the delete, only the old entity type and old entity ID. To address this use case, we should offer a delete() method that requires only the entity type and entity ID. This method would only work if the ID mapping and RoutingKeyBridge properly implement methods that work even without a full entity; otherwise the delete() method would throw an exception. This would be mainly useful for Infinispan, but maybe also for ORM, if we can somehow pass the old value of the property used to generate the document ID (i.e. move document ID extraction from the POJO mapper to the ORM integration).
Note: if possible, we should also add a safeguard when examining the dirty properties. If a path the @DocumentId depends is marked as dirty in an update() even, something is afoul and we should definitely throw an exception (suggest to use delete(), then add()). |