2016-11-15 29 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 }