我正在尝试在rails上的ruby中实现弹性搜索。在我的患者页面上,当我包含循环时,我收到以下错误
Elasticsearch :: Transport :: Transport :: Errors :: NotFound in Patients #index
显示/home/ubuntu/workspace/shc-pms/app/views/patients/index.html.erb第29行:
[404] {“error”:“IndexMissingException [[patient] missing]”,“status”:404}
这是索引代码
<h1>Dr Ross Kings Patients</h1>
<div>
<%= link_to "New Patient", new_patient_path %>
</div>
<div class="row">
<%= form_tag patients_path, role: 'search', method: :get do |f| %>
<div class="form-group">
<%= text_field_tag :q, params[:q], class: 'form-control' %>
</div>
<%= button_tag "Search", class: 'btn btn-default', name: nil %>
<% end %>
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Phone</th>
<th>Ailment</th>
<th>Apointment</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<% @patients.each do |patient| %>
<tr>
<td><%= link_to patient.name, patient_path(patient) %></td>
<td><%= patient.age %></td>
<td><%= patient.phone %></td>
<td><%= patient.ailment %></td>
<td><%= patient.apointment %></td>
<td><%= patient.status %></td>
<td><%= link_to "Back", patients_path %></td>
<td><%= link_to "Edit", edit_patient_path(patient)%></td>
<td><%= link_to( "Delete", patient_path(patient), data: {confirm: "Are you sure you want to delete: #{patient.name}?"},method: :delete) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
这是患者模型
class Patient < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
validates :name, presence:true
validates :age, presence:true
validates :phone, presence:true
validates :ailment, presence:true
validates :apointment, presence:true
validates :status, presence:true
belongs_to :user
def to_s
name
end
end
这是患者控制器上的索引方法
def index
@patients = current_user.patients.search((params[:q].present? ? params[:q] : '*')).records
end
我还安装了这些宝石
gem 'elasticsearch-rails'
gem 'elasticsearch-model'