创建索引时,Elasticsearch :: Transport :: Transport :: Errors :: BadRequest [400]

时间:2017-01-06 21:44:40

标签: ruby-on-rails ruby ruby-on-rails-4 elasticsearch

在我的rails应用程序中使用' elasticsearch-model'和' elasticsearch-rails'在默认端口上运行的gems installed和elasticsearch(v5.1.1)以及看起来像这样的模型

class Article
  include Mongoid::Document
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  field :title, type: String
  field :author, type: String

  index_name "articles-#{Rails.env}"
end

初始化程序就是这样的

Elasticsearch::Model.client = Elasticsearch::Client.new host: ENV['ELASTICSEARCH_URL'] || "http://localhost:9200/"

当我尝试导入或创建索引

Article.import force:true
Article.__elasticsearch__.create_index! force: true 

我收到以下错误

 Elasticsearch::Transport::Transport::Errors::BadRequest: [400] No handler found for uri [//articles-development] and method [DELETE]
  from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/transport/base.rb:201:in `__raise_transport_error'
  from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/transport/base.rb:312:in `perform_request'
  from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
  from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/client.rb:128:in `perform_request'

2 个答案:

答案 0 :(得分:2)

经过一番调查后,问题出在我的初始化程序上。它在改变主机后起作用。

Elasticsearch::Model.client = Elasticsearch::Client.new host: ENV['ELASTICSEARCH_URL'] || "localhost:9200"

<强>更新 显然配置适用于Elasticsearch 2.4.x.

答案 1 :(得分:0)

在我的情况下,从以下位置更改.env或您保存在任何位置的DATABASE_URL格式:

DATABASE_URL=postgres:/myapp_development?pool=5

收件人:

DATABASE_URL=postgresql://user:password@localhost:5432/myapp_development