简体   繁体   English

如何在Heroku上使用Elasticsearch

[英]How to use Elasticsearch on Heroku

I've just finished watching both Railscasts' episodes on Elasticsearch . 我刚刚在Elasticsearch上观看了两个Railscast的剧集。 I've also went ahead and implemented it into my rails application (3.1) and everything is working great. 我也继续将它实现到我的rails应用程序(3.1)中,一切都运行良好。 How I want to deploy my app to Heroku but I'm unsure how to get Elasticsearch working on Heroku (specifically on a cedar stack). 我如何将我的应用程序部署到Heroku,但我不确定如何让Elasticsearch在Heroku上运行 (特别是在雪松堆栈上)。

Any help would be greatly appreciated! 任何帮助将不胜感激!

You can very easily [and freely ;-)] roll your own ElasticSearch server on Amazon EC2, and just connect to it with your app. 您可以非常轻松地[和自由地;-)]在Amazon EC2上滚动您自己的ElasticSearch服务器,并使用您的应用程序连接到它。 This is what we're doing, and it's working nicely... 这就是我们正在做的事情,它运作良好......

http://www.elasticsearch.org/tutorials/elasticsearch-on-ec2/ http://www.elasticsearch.org/tutorials/elasticsearch-on-ec2/

Heroku now supports ElasticSearch with the Bonsai add on. Heroku现在支持ElasticSearch并添加Bonsai。 https://devcenter.heroku.com/articles/bonsai https://devcenter.heroku.com/articles/bonsai

I created a Play framework module that will run Elastic Search on Heroku using S3 to persist the state. 我创建了一个Play框架模块,它将使用S3在Heroku上运行Elastic Search以保持状态。 No need for an EC2 instance - you only pay for the cost of S3 data which is much less - mainly IO transactions. 不需要EC2实例 - 您只需支付更少的S3数据成本 - 主要是IO事务。 It uses the ElasticSearch S3 gateway (persistence mechanism). 它使用ElasticSearch S3网关(持久性机制)。

You can use it either by extending the Play application to create specific endpoints for your search functions, or if you like, you can access ElasticSearch REST API directly (by default it exposes it on the route http://yourapp.com/es ). 您可以通过扩展Play应用程序为您的搜索功能创建特定端点来使用它,或者如果您愿意,可以直接访问ElasticSearch REST API(默认情况下,它会在路由http://yourapp.com/es上公开它) 。 There is a very basic authentication system to secure it. 有一个非常基本的身份验证系统来保护它。

The only downside to this setup is that the dyno can take some time to spin up. 这种设置的唯一缺点是dyno可能需要一些时间才能启动。 So, it won't work well if you let the dyno spin down from inactivity - and you may get nailed for S3 data transfer charges if that happens a lot and your index is huge. 因此,如果你让dyno从不活动状态中减少,那么它将无法正常工作 - 如果发生了很多并且你的索引很大,你可能会因S3数据传输费用而被钉死。 The upside is you control your own data and it is cheap cheap cheap. 好处是你控制自己的数据,便宜便宜。 Another word of warning - you will need to be careful to keep inside the memory limits of a Heroku dyno. 另一个警告 - 你需要小心保持Heroku dyno的记忆限制。 That said, we had full text search autocomplete functions working on several indexes with no problems. 也就是说,我们有全文搜索自动完成功能在几个索引上工作,没有任何问题。

You might be able to build a similar module in Rails using JRuby to talk to the ElasticSearch Java API. 您可以使用JRuby在Rails中构建类似的模块,以与ElasticSearch Java API进行通信。 My main contribution here was figuring out how to run it inside another web framework - since Play also uses Netty it was pretty easy to embed it. 我在这里的主要贡献是弄清楚如何在另一个Web框架中运行它 - 因为Play也使用Netty,它很容易嵌入它。 Performance tests compared to an EC2 cluster + Tire (Rails gem for ElasticSearch) showed that the Heroku/Play approach performed faster searches. 与EC2集群+ Tire(ElasticSearch的Rails gem)相比,性能测试显示Heroku / Play方法执行的搜索速度更快。

The project is here: https://github.com/carchrae/elastic-play - I'd be happy to help people set it up - it should be pretty painless. 该项目在这里: https//github.com/carchrae/elastic-play - 我很乐意帮助人们设置它 - 它应该是非常轻松的。

这是我第一次看到RailsCast时的想法,但遗憾的是它是一个java守护进程,它在Heroku上无法运行。

Anyway you can't run it on a normal Heroku dyno since it would have to save data to disk which is not persisted on Heroku. 无论如何你不能在普通的Heroku dyno上运行它,因为它必须将数据保存到Heroku上不存在的磁盘上。 You need to wait for an Add-on or host it somewhere else. 您需要等待加载项或将其托管在其他位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM