【问题标题】:Bonsai: Use create_index! or the :force option to create it盆景:使用create_index!或 :force 选项来创建它
【发布时间】:2017-01-08 17:35:51
【问题描述】:

在过去的 4 周里,我一直在与 Bonsai 和 Elasticsearch 进行一场失败的战斗,这在某种程度上令人沮丧,因为几个月前我还在另一个应用程序上使用它。
我的应用程序崩溃了,当我转到 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 heroku run rails console 中运行 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'

【问题讨论】:

  • 男人!检查此answer,它可能会对您有所帮助。祝你好运!

标签: ruby-on-rails heroku


【解决方案1】:

只需使用Service.import(force: true) 即可导入数据。

如果索引已经存在,则在导入数据前删除索引并重新创建。

如果索引不存在,则直接创建索引并导入数据。

所以不再需要Service.__elasticsearch__.create_index!

【讨论】:

    猜你喜欢
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2015-01-21
    • 1970-01-01
    • 2013-10-13
    • 2016-08-01
    • 2021-08-01
    相关资源
    最近更新 更多