我正在尝试在 rails 项目中运行弹性搜索,但出现错误:
[ERROR] 创建索引时出现错误——elasticsearch返回:
405 : {"error":"URI [/articles] 和方法 [POST] 的 HTTP 方法不正确,允许:[GET, DELETE, PUT, HEAD]","status":405}
[IMPORT] 删除索引 'articles' [IMPORT] 使用映射创建索引 'articles':
{"article":{"properties":{"title":{"type":"string"},"category_name":{"boost":10,"type":"string"}}}}
[ERROR] 创建索引时出现错误——Elasticsearch 返回:
405 : {"error":"URI [/articles] 和方法 [POST] 的 HTTP 方法不正确,允许:[GET, DELETE, PUT, HEAD]","status":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 环境轮胎:import CLASS=Article FORCE=true
我需要在 localhost:3000 本身上运行它,而不是在任何 /links 上运行它,但会出现错误
提前致谢