我正在尝试在rails项目中运行弹性搜索,但收到错误:
[错误]创建索引时出错 - 返回了elasticsearch:
405:{"错误":" uri [/ articles]和方法[POST]的HTTP方法不正确,允许:[GET,DELETE,PUT,HEAD]", "状态" 405}
[导入]删除索引'文章' [导入]创建索引'文章'与映射:
{"物品" {"属性" {"标题" {"类型":"串&#34 ;}" CATEGORY_NAME" {"升压":10,"类型":"串"}}}}
[错误]创建索引时出错 - Elasticsearch返回:
405:{"错误":" uri [/ articles]和方法[POST]的HTTP方法不正确,允许:[GET,DELETE,PUT,HEAD]", "状态" 405}
以下是我的文章模型的样子:
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :id, type: 'integer'
# indexes :author_id, type: 'integer'
indexes :title
indexes :category_name, boost: 10
indexes :content # analyzer: 'snowball'
indexes :created_at, type: 'date'
indexes :published_comments, type: 'integer'
end
def self.search(params)
tire.search(page: params[:page], per_page: 2) do
query do
boolean do
must { string params[:query], default_operator: "AND" } if params[:query].present?
must { range :published_at, lte: Time.zone.now }
must { term :author_id, params[:author_id] } if params[:author_id].present?
end
end
sort { by :published_at, "desc" } if params[:query].blank?
facet "authors" do
terms :author_id
end
# raise to_curl
end
end
下面是我有搜索框和按钮的表单:
<div class="col-6 col-md-5">
<%= form_tag @articles_path,:html => {class: "input-group rounded"}, method: :get do %>
<%= text_field_tag :query, params[:query],placholder: "Search the entire site",class: "form-control w-100 g-brd-secondary-light-v2 g-brd-primary--focus g-color-secondary-dark-v1 g-placeholder-secondary-dark-v1 g-bg-white g-font-weight-400 g-font-size-13 rounded g-px-20 g-py-12" %>
<span class="input-group-addon g-brd-none g-py-0 g-pr-0">
<%= submit_tag "Search", name: nil , class: "btn u-btn-white g-color-primary--hover g-bg-secondary g-font-weight-600 g-font-size-13 text-uppercase rounded g-py-12 g-px-20"%>
</span>
<% end %>
</div>
请帮助我做什么我从一个多星期以来一直在研究解决方案。
我在railscasts视频后实现了这个: http://railscasts.com/episodes/307-elasticsearch-part-2
我使用rails索引elasticsearch:
rake environment tire:import CLASS = Article FORCE = true
我需要在localhost:3000本身上运行它,而不是在任何/链接上运行它 但是收到错误
提前致谢