Searchkick index is empty after reindexing from model
def self.reindex_course index = Course.reindex(async: true, refresh_interval: "5s") Course.search_index.promote(index[:index_name], update_refresh_interval: true) Course.search_index.clean_indices end
Looks like calling Course.search_index.clean_indices
in the last line would clean old indices. I think you may want to call it in the first line, or do not call it at all.
I found a quick fix for this issue. calling touch
on parent(Course
) class of Instructor
and other associated model seems to be updating the index correctly.
instructor.rb
model looks like this:
:::after_commit :reindex_course::def reindex_course if self.try(:instructorable).try(:persisted?) if self.instructorable_type == "Course" self.instructorable.touch elsif self.instructorable_type == "ScheduledCourse" self.instructorable.course.touch end end end
As the hook works correctly when something happens on Course
model, touch
seems to be solving the purpose for now.
Answer to the problem remains a mystery to me.