我有一个名为的模型Movie
,如下所示:
class Movie < ActiveRecord::Base include Elasticsearch::Model include Elasticsearch::Model::Callbacks has_many :actors, after_add: [ lambda {|a,c| a.__elasticsearch__.index_document}], after_remove: [ lambda {|a,c| a.__elasticsearch__.index_document}] settings index: {number_of_shards: 1} do mappings dynamic: 'false' do indexes :title, analyzer: 'snowball', boost: 100 indexes :actors end end def as_indexed_json(options={}) self.as_json( include: { actors: { only: :name} } ) end end
当我这样做时Movie.first.as_indexed_json
,我得到:
{"id"=>6, "title"=>"Back to the Future ", "created_at"=>Wed, 03 Dec 2014 22:21:24 UTC +00:00, "updated_at"=>Fri, 12 Dec 2014 23:40:03 UTC +00:00, "actors"=>[{"name"=>"Michael J Fox"}, {"name"=>"Christopher Lloyd"}, {"name"=>"Lea Thompson"}]}
但是当我Movie.search("Christopher Lloyd").records.first
得到时:=> nil
.
我可以对索引进行哪些更改来搜索与搜索到的actor相关联的电影?