如何使用“弹性搜索”专门使用弹性搜索与导轨应用程序宝石 [英] How to integrate elasticsearch with rails application specifically using "Elasticsearch" gem

查看:150
本文介绍了如何使用“弹性搜索”专门使用弹性搜索与导轨应用程序宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的,还有弹性搜索。我已经看到了使用Tire,Searchkick和其他一些配置的其他资源,但是我想使用 Elasticsearch gem。我在我的系统上运行rails应用程序并运行Elasticsearch服务器,但是我没有如何配置它们进行通信。

I am new to rails and as well to elastic search. I have seen other resources to configure using Tire, Searchkick and some others, but I want to use Elasticsearch gem. I have running rails application and running Elasticsearch server on my system but I do not how to configure them to communicate with each other.

目前,我面临很多麻烦,要做同样的事情。任何帮助将被高度赞赏。

Currently, I am facing a lot of troubles to do the same. Any help would be highly appreciated.

推荐答案

对于一个非常基本的快速启动弹性的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

这篇关于如何使用“弹性搜索”专门使用弹性搜索与导轨应用程序宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆