- 
  Notifications
 
You must be signed in to change notification settings  - Fork 810
 
add index_on_update! option #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey, this feels like a bandaid for the problems with update_document not picking up the "correct" JSON serialization of the model -- many issues are opened for that... I absolutely do think that something can be improved here, but preferably on a different level than a magical class level method? Some other way of configuration, different kind of introspection we do, etc...
I agree that there is probably a better way. In the project that I'm working on I would always want to call index_document on update and never update_document because there is content that is fetched from an external service that ActiveModel::Dirty doesn't know anything about. So, while it sounds important to improve update_document, it would never be right for me in this case. What do you think would be the "right" way specify that the indexing method that should be used on update?
Hmm, if that is the case, why not simply implement the after_save etc. hooks yourself, as documented in https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md#custom-callbacks? (The "automatic callbacks" are really just a starting point,a default.)
Yeah. You're totally right. I had been thinking that the callbacks were more tied than they are to Elasticsearch::Model. I'm not sure why since I had read the code! Tired eyes 😴 😴 😴
I can totally understand that, what worries me that despite all the effort in the README to state that it's just a "starting point", people try to augment/customize/etc the default callbacks, instead of writing the three lines of Ruby to solve a problem cleanly :)
I needed to always index on update for some
ActiveRecordclasses. This provides anindex_on_update!method to set that behavior for a class. I did not add tests for it yet but could.