2016-11-15 49 views
0
class Doctor < ActiveRecord::Base 

    has_many :doctors_doctor_branches, foreign_key: "doctor_id", dependent: :destroy 
    has_many :doctor_branches, through: :doctors_doctor_branches 

    def as_indexed_json(options={}) 
    as_json(
     include: { 
     doctor_branches: {only: [:id, :name]} 
     } 
    ) 
    end 
end 

关系是正确的,因为为什么弹性搜索不索引的相关医生和DoctorBranch之间

Doctor.find(1).doctor_branches 

给我AR阵列。但是当我做

response = Doctor.__elasticsearch__.search 'Yoga' 

我没有得到响应结果。

回答

0

您是否创建了索引?为此,您需要运行类似以下的代码:

client  = Doctor.gateway.client 
index_name = Doctor.index_name 
settings = Doctor.settings.to_hash 
mappings = Doctor.mappings.to_hash 
client.indices.create index: index_name, 
         body: { 
         settings: settings.to_hash, 
         mappings: mappings.to_hash }