gpt4 book ai didi

ruby-on-rails - Bonsai : Use create_index! 或 :force 选项来创建它

转载 作者:行者123 更新时间:2023-12-03 14:11:54 26 4
gpt4 key购买 nike

在过去的 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 中运行 rails 控制台时 heroku run rails console我得到几乎相同的错误:
/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)导入数据。

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

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

所以不需要Service.__elasticsearch__.create_index!了。

关于ruby-on-rails - Bonsai : Use create_index! 或 :force 选项来创建它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39261283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com