我正在尝试在 rails 项目中运行弹性搜索,但出现错误:
[ERROR] 创建索引时出现错误——elasticsearch 返回:
405:{"error":"URI [/articles] 和方法 [POST] 的 HTTP 方法不正确,允许:[GET、DELETE、PUT、HEAD]","status":405}
[导入] 删除索引“文章” [导入] 使用映射创建索引“文章”:
{"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: …Run Code Online (Sandbox Code Playgroud)