簡體   English   中英

Elasticsearch::Transport::Transport::Errors::BadRequest [400] 創建索引時

[英]Elasticsearch::Transport::Transport::Errors::BadRequest [400] while creating index

在我安裝了“elasticsearch-model”和“elasticsearch-rails”gems 的 rails 應用程序中,並在默認端口上運行 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'

經過一番調查,問題出在我的初始化程序上。 更換主機后就可以使用了。

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

更新顯然該配置適用於 Elasticsearch 2.4.x。

在我的場景中,更改 DATABASE_URL 格式,在.env或任何你保存它的地方,從:

DATABASE_URL=postgres:/myapp_development?pool=5

到:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM