更新时间:2023-02-19 08:02:49
对于一个非常基本的快速启动弹性的github宝石的模型索引,你可以做以下在开发环境中,弹性搜索在localhost上运行:9200
For a very basic quick start of the elastic's github gem for model indexing you could do the following in development environment with elasticsearch running on localhost:9200
在Gemfile中:
gem 'elasticsearch-model'
然后在终端上运行:
$ bundle install
app / models / service.rb包括后面的声明:
in app/models/service.rb include right after class declaration:
include Elasticsearch::Model
您现在可以使用现有数据在控制台上播放(结果仅仅是一个例子):
you can now play with it on console with existing data (results are just an example):
$ 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
有关更多信息和详细信息,您可以查看项目的 github页面
For more information and details you can take a look at the project's github page