在我的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'
答案 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