2

我有一个 Ruby on rails 3.2 应用程序。我想在已经填充了大量数据的模型上启用基于文本的搜索。假设模型类的名称是 Post。我计划使用 elasticsearch,因为我听说它是​​最好的实时搜索引擎之一,并且我正在使用轮胎 gem,以便我的应用程序可以与 elasticsearch 交互。

由于我是弹性搜索的新手,因此在为模型的现有数据创建索引时遇到了麻烦。我使用 mongodb 作为后端数据库。谁能告诉我如何导入索引。

我已经试过了

Tire.index "posts" do
  import Post.all
end

我得到的错误是:

  BSON::InvalidObjectId: illegal ObjectId format: Career Guidance 
  from /Users/anirvan/.rvm/gems/ruby-1.9.3-p125/gems/bson-1.5.1/lib/bson/types/object_id.rb:126:in `from_string'

有谁可以帮我离开这里吗 ?

4

1 回答 1

7

I use Mysql and this code in bash(from railscasts.com):

rake environment tire:import CLASS=Post FORCE=true

http://www.elasticsearch.org/guide/appendix/clients.html

tire: Ruby API & DSL, with full Rails ActiveModel compatibility and mongoid integration through mebla.

Try it, maybe help you.

于 2012-04-23T13:00:30.117 回答