简体   繁体   中英

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

In my rails application with 'elasticsearch-model' and 'elasticsearch-rails' gems installed and elasticsearch (v5.1.1) running on the default port and a model that looks like this

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

And the initializer is something like this

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

When I try to import or create index

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

I get the following error

 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'

After some investigation the issue was with my initializer. it worked after changing the host.

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

Update Apparently the configuration works with Elasticsearch 2.4.x.

In my scenario, changing DATABASE_URL format, in .env or wherever You keep it, from:

DATABASE_URL=postgres:/myapp_development?pool=5

to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM