加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何使用“Elasticsearch”gem将elasticsearch

发布时间:2020-12-16 19:19:30 所属栏目:百科 来源:网络整理
导读:我是新手,也是弹性搜索的新手.我已经看到使用Tire,Searchkick和其他一些配置的其他资源,但我想使用Elasticsearch gem.我有运行rails应用程序并在我的系统上运行Elasticsearch服务器,但我不知道如何配置它们以便彼此通信. 目前,我也面临着很多麻烦.任何帮助将
我是新手,也是弹性搜索的新手.我已经看到使用Tire,Searchkick和其他一些配置的其他资源,但我想使用Elasticsearch gem.我有运行rails应用程序并在我的系统上运行Elasticsearch服务器,但我不知道如何配置它们以便彼此通信.

目前,我也面临着很多麻烦.任何帮助将受到高度赞赏.

解决方法

对于用于模型索引的弹性 github gem的非常基本的快速启动,您可以在开发环境中执行以下操作,并在localhost上运行elasticsearch:9200

在Gemfile中:

gem 'elasticsearch-model'

然后在终端上运行:

$bundle install

在app / models / service.rb中包括课后声明:

include Elasticsearch::Model

您现在可以在控制台上使用现有数据进行播放(结果只是一个示例):

$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 page

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读