As a developer, I would like to see an example of an index which is derived from multiple Ruby models. Based on the documentation today, I only see indices with a single index_scope defined. I am actually not sure if it is possible today, but I would like to update my Elasticsearch documents multiple-model associations:
class Employee < ActiveRecord::Base
# TODO: How to update specific `restaurant` document(s)?
# update_index('restaurant') { ??? }
end
class Cuisine < ActiveRecord::Base
# TODO: How to update specific `restaurant` document(s)?
# update_index('restaurant') { ??? }
end
class Restaurant < ActiveRecord::Base
has_many :employees
has_many :cuisines
update_index('restaurant') { self }
end
class RestaurantsIndex < Chewy::Index
index_scope Restaurant
end
In this contrived example, a Restaurant would have a foreign key relationship with Employee and Cuisine, but an Employee nor a Cuisine do not necessarily belong to a Restaurant. Therefore, when the associated records update, the RestaurantsIndex would miss these updates, correct? How can we ensure our index is always up-to-date with our DB record associations?
As a developer, I would like to see an example of an index which is derived from multiple Ruby models. Based on the documentation today, I only see indices with a single
index_scope
defined. I am actually not sure if it is possible today, but I would like to update my Elasticsearch documents multiple-model associations:In this contrived example, a
Restaurant
would have a foreign key relationship withEmployee
andCuisine
, but anEmployee
nor aCuisine
do not necessarily belong to aRestaurant
. Therefore, when the associated records update, theRestaurantsIndex
would miss these updates, correct? How can we ensure our index is always up-to-date with our DB record associations?I did come across https://github.com/toptal/chewy/issues/34 before making this issue. However, this seems to reference an older syntax / version of Chewy.