Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 967
Giridhar Bandi Avatar asked Jan 06 '17 21:01

Giridhar Bandi


1 Answers

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.

like image 101
Giridhar Bandi Avatar answered Sep 18 '22 16:09

Giridhar Bandi