thenativeweb / node-cqrs-eventdenormalizer

Node-cqrs-eventdenormalizer is a node.js module that implements the cqrs pattern. It can be very useful as eventdenormalizer component if you work with (d)ddd, cqrs, domain, host, etc.
http://cqrs.js.org/pages/eventdenormalizer.html
MIT License
38 stars 27 forks source link

ElasticSearch6: vm.actionOnCommit==='update' gives status:404 #74

Closed daschy closed 6 years ago

daschy commented 6 years ago

Hi,

I am denormalizing 2 events in replay mode.

They are alway saved and executed in order, by the denormalizers.

Although after the 2nd denormalizer the vm.actionOnCommit is 'update'. Only when the 2nd denormalizer is executed the ViewModel is passed to the bulkCommit(...). To the bulkCommit(...) arrives only vm.actionOnCommit='update'. (https://github.com/adrai/node-viewmodel/blob/master/lib/databases/elasticsearch6.js#L225 ). So only the operation "update" is pushed to the elasticsearch . Because the record does not exist, the update fails. Based on my observations, this issue occurs whenever the is more than 1 event for one aggregate (ie: revision > 1).

My suggestion is to 'upsert' the record when vm.actionOnCommit is 'update', by using the 'index' operation. (similarly to what is done in the mongo driver , https://github.com/adrai/node-viewmodel/blob/master/lib/databases/mongodb.js#L296 )

Am I missing something?

Thanks

adrai commented 6 years ago

@nanov fyi

nanov commented 6 years ago

sorry for the late replay, and thank you for reporting the issue, fix is on the way.

nanov commented 6 years ago

This should resolve the issue.

I didn't go with upset becuase of the versioning mechanism ( mongo implementation is not using upsert as well ).

The problem may still persist by multiple updates ( create->update->update) because of the same mechanism, needs to be tested.

nanov commented 6 years ago

with this commit, everything should work as expected. Would love to hear your feedback.

daschy commented 6 years ago

@nanov It is still not working. The reason is when, in replay mode, I have:

Because is hitting only case 'update' on a not existing aggregate the operation fails (reason: '[acme.topic][5a7098ff6c54913cff9a854a]: document missing').

Any ideas ?

Thanks

M.

nanov commented 6 years ago

i see, update coming.

nanov commented 6 years ago

I own you an apology, your original suggestion ( upsert ) was the way to go ( it is done in a similar manner during normal commit since the very beginning ). Not only it solves the problem, it makes the code shorter.

Please let me know if everything works as expected now.

daschy commented 6 years ago

@nanov works as expected, thanks a lot for the fast responses and fixes