在过去的4周里,我一直在与Bonsai和Elasticsearch进行一场激烈的战斗,这在某种程度上令人沮丧,因为几个月前我让它在另一个应用程序上工作.
我的应用程序崩溃了,当我去Heroku时,我得到了“应用程序错误”警告.当我查看Herkou Logs时,我发现了一些我认为是问题的东西:
我的应用程序崩溃了,当我去Heroku时,我得到了“应用程序错误”警告.当我查看Herkou Logs时,我发现了一些我认为是问题的东西:
2016-08-31T23:23:47.189996+00:00 heroku[web.1]: Process exited with status 1 2016-09-01T00:12:50.088164+00:00 heroku[web.1]: State changed from crashed to starting 2016-09-01T00:12:57.130922+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 14657 -e production` 2016-09-01T00:13:00.947244+00:00 app[web.1]: => Booting WEBrick 2016-09-01T00:13:00.947263+00:00 app[web.1]: => Rails 4.2.5.1 application starting in production on http://0.0.0.0:14657 2016-09-01T00:13:00.947264+00:00 app[web.1]: => Run `rails server -h` for more startup options 2016-09-01T00:13:00.947265+00:00 app[web.1]: => Ctrl-C to shutdown server 2016-09-01T00:13:00.947266+00:00 app[web.1]: Exiting 2016-09-01T00:13:00.947281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/elasticsearch-model-0.1.9/lib/elasticsearch/model/importing.rb:118:in `import': professors does not exist to be imported into. Use create_index! or the :force option to create it. (ArgumentError) 2016-09-01T00:13:00.947282+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.3.0/gems/elasticsearch-model-0.1.9/lib/elasticsearch/model.rb:116:in `import' 2016-09-01T00:13:00.947283+00:00 app[web.1]: from /app/app/models/professor.rb:31:in `<top (required)>'
特别是这一行:
import': professors does not exist to be imported into. Use create_index! or the :force option to create it. (ArgumentError)
在Localhost上一切正常,但它与Heroku崩溃.我发现this question我认为与我的相似,其中一个答案是尝试:
$rails console # Create the index for Service model on elasticsearch > Service.__elasticsearch__.create_index! => {"ackNowledged"=>true} # Import current Service records into the index > Service.import Service Load (207.3ms) SELECT "services".* FROM "services" ORDER BY "services"."id" ASC LIMIT 1000 # Sample search returning total results > Service.__elasticsearch__.search("mykeyword").results.total => 123
但每当我在Heroku中运行rails控制台时,heroku运行rails控制台我得到了几乎相同的错误:
/app/vendor/bundle/ruby/2.3.0/gems/elasticsearch-model-0.1.9/lib/elasticsearch/model/importing.rb:118:in `import': professors does not exist to be imported into. Use create_index! or the :force option to create it. (ArgumentError) from /app/vendor/bundle/ruby/2.3.0/gems/elasticsearch-model-0.1.9/lib/elasticsearch/model.rb:116:in `import'
解决方法
只需使用Service.import(force:true)即可导入数据.
如果索引已经存在,它将删除索引并在导入数据之前重新创建它.
如果索引不存在,它将直接创建索引和导入数据.
所以不需要服务.__ elasticsearch __.create_index!了.