Save specific fields with elasticsearch-model in Rails -


i'm using elasticsearch-model gem in rails 4 project store users in mysql , elasticsearch. in project, elasticsearch part used find people of mysql fields geo_point, birthdate, gender, etc... not every fields i've in mysql "users" table useful user's search.

so, i'd store users fields in mysql , fields needed user's search in elasticsearch.

to store required fields on create, i've overrided method 'as_indexed_json' , used :

as_json(only: ['id', 'gender', 'location'] 

on create, things work great. when i'm updating user fields should saved in mysql only, adds elasticsearch anyway.

for instance, user model have "id", "gender", "is_premium", "status", "created_at", "birthdate", "location". in elasticsearch i'd save "id", "gender", "birthdate", "location"

how can this? help.

this issue elasticsearch-rails (see github).

in nutshell default update callback calls update_document doesn't use as_indexed_json: uses activemodel::dirty send changed columns.

you can fix either overriding update_document method includes want, or changing callback does, example

after_commit on: [:create, :update]   index_document end  after_commit on: [:destroy]   delete_document end 

instead of using default callbacks module result in index_document being used, 'dumb' full update rather trying send deltas.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -