loopbackio / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
79 stars 55 forks source link

add support for replaceById operation #49

Closed juanpujol closed 5 years ago

juanpujol commented 8 years ago

This fixes the exeption when running: POST /Model/{id}/replace

Error: The connector elasticsearch does not support replaceById operation. This is not a bug in LoopBack. Please contact the authors of the connector, preferably via GitHub issues.

closes #48

slnode commented 8 years ago

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

bajtos commented 8 years ago

@juanpujol thank you for the pull request!

I am personally not familiar with ES to judge whether this is a correct implementation.

The difference between updateAttributes and replaceById is that the first operation should perform a partial update (patch only the properties provided in the request, leave other properties untouched), while the second operation should replace the whole instance.

current instance:
{ "name": "Miroslav", "handle": "bajtos" }

updateAttributes({"name": "Miroslav Bajtos"})
  results in { "name": "Miroslav Bajtos", "handle": "bajtos" }

replaceById({"name": "Alter Ego" })
  results in { "name": "Alter Ego" }
  (handle was removed)
bajtos commented 8 years ago

@slnode ok to test

juanpujol commented 8 years ago

@bajtos thank you, that's a good observation.

Just updated the PR to use the index API when calling replaceById that should take care of the scenario you described.

pulkitsinghal commented 7 years ago

@juanpujol - would you be able to contribute some tests as well? I can get you started via a skype session or something similar. PM me on gitter.im for my skype handle