我正在运行搜索和弹性搜索,并且我一直在尝试重新创建我的索引,因为我的rails应用程序正在崩溃,但这也一直在失败。我对此非常陌生,所以感到非常失落。
我运行rake environment elasticsearch:import:all FORCE=y
但错误是
Starting up a new ElasticSearch client with
[IMPORT] Loading models from: /home/ubuntu/workspace/sample_app/app/models
2016-03-11 16:32:07 +0000: [Faraday::ConnectionFailed] Connection refused - connect(2) for "localhost" port 9200 {:host=>"localhost", :port=>9200, :protocol=>"http"}
rake aborted!
ArgumentError: users does not exist to be imported into. Use create_index! or the :force option to create it.
/usr/local/rvm/gems/ruby-2.2.1/gems/elasticsearch-model-0.1.8/lib/elasticsearch/model/importing.rb:118:in `import'
/usr/local/rvm/gems/ruby-2.2.1/gems/elasticsearch-model-0.1.8/lib/elasticsearch/model.rb:115:in `import'
/home/ubuntu/workspace/sample_app/app/models/user.rb:109:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:457:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:457:in `block in load_file'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:647:in `new_constants_in'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:456:in `load_file'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:354:in `require_or_load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:494:in `load_missing_constant'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:184:in `const_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/inflector/methods.rb:261:in `const_get'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/inflector/methods.rb:261:in `block in constantize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/inflector/methods.rb:259:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/inflector/methods.rb:259:in `inject'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/inflector/methods.rb:259:in `constantize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/usr/local/rvm/gems/ruby-2.2.1/gems/elasticsearch-rails-0.1.8/lib/elasticsearch/rails/tasks/import.rb:93:in `block (4 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/elasticsearch-rails-0.1.8/lib/elasticsearch/rails/tasks/import.rb:87:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/elasticsearch-rails-0.1.8/lib/elasticsearch/rails/tasks/import.rb:87:in `block (3 levels) in <top (required)>'
Tasks: TOP => elasticsearch:import:all
(See full trace by running task with --trace)
答案 0 :(得分:2)
今天早上我们遇到了同样的问题。
elastic-search-model文档告诉您如下设置模型:
class User < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
#The rest of your mode...
end
User.import
但在导入现有数据之前,您需要删除User.import
,然后运行rake environment elasticsearch:import:all FORCE=y
,一切都会顺利进行。
请务必在运行rake任务后添加User.import
,以便正确导入新用户。
快乐的编码!
答案 1 :(得分:0)
在rails控制台中尝试YourModelName.import(force: true)
。