【问题标题】:Elasticsearch::Transport::Transport::Errors::NotFound ([404] {"error":{"root_cause":[{"type":"index_not_found_exception"Elasticsearch::Transport::Transport::Errors::NotFound ([404] {"error":{"root_cause":[{"type":"index_not_found_exception"
【发布时间】:2018-04-13 06:36:07
【问题描述】:

不确定在本地环境中使用 elasticsearch 工作时遇到这个奇怪的错误,如果有任何帮助,我将不胜感激。谢谢

Elasticsearch::Transport::Transport::Errors::NotFound ([404] {"错误":{"root_cause":[{"type":"index_not_found_exception","re​​ason":"no 这样的 index","re​​source.type":"index_or_alias","re​​source.id":"invoices","index":"invoices"}],"type":"index_not_found_exception","re​​ason":"no 这样的 index","re​​source.type":"index_or_alias","re​​source.id":"invoices","index":"invoices"},"status":404})

【问题讨论】:

  • 你能解释一下你在做什么吗?该错误只是表示您正在访问的invoices 索引在您的本地 ES 服务器中不存在。
  • @Val 您好,感谢您的回复,实际上弹性搜索已在我现有的项目中使用,并且在任何地方都可以正常工作,但在 invoice 模型的情况下却不行,而且我是弹性搜索的新手。我已经用控制器代码更新了这个问题,你能看看那里吗?
  • 这告诉我的只是您的本地服务器中没有任何数据。您是否忘了先创建索引并加载数据?
  • @Val 我在发票表中有 5 条记录。并且不确定索引的东西。
  • “表”是什么意思。 Elasticsearch 没有任何表,但它有索引。您的数据库中是否有据称与您的 Elasticsearch 服务器同步的数据?

标签: ruby-on-rails elasticsearch elasticsearch-rails


【解决方案1】:

通过在rails console 运行这些命令来索引 ES 来修复问题:-

Model.__elasticsearch__.create_index!
Model.__elasticsearch__.create_index! force: true
Model.import force: true 

【讨论】:

  • 您只需要Model.import(force: true) - 这将创建索引然后进行导入
  • 这解决了我得到的与 OP 相似或可能相同的错误。但是这些行已经在 rails_helper.rb 中,我应该怎么做才能不手动运行它们而是让它自动运行?
【解决方案2】:

您也可以按照我在rubydoc 网站上找到的这些步骤操作:

需要在您的应用程序中定义任务,例如。在 lib/tasks/elasticsearch.rake 文件中:

require 'elasticsearch/rails/tasks/import'

要从您的模型中导入记录,请运行:

bundle exec rake environment elasticsearch:import:model CLASS='ModelName'

或者你可以使用:

rake environment elasticsearch:import:all DIR=app/models

导入所有模型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多