我有一個名爲Movie
模型,看起來像這樣:Elasticsearch軌/ Elasticsearch新型檢索模型關聯
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
。
我可以對索引做些什麼改變來搜索與搜索到的演員相關的電影?
我有同樣的困境,你有沒有這方面的任何答覆? – Finks