简体   繁体   中英

How to use Elasticsearch on Heroku

I've just finished watching both Railscasts' episodes on Elasticsearch . I've also went ahead and implemented it into my rails application (3.1) and everything is working great. 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).

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. This is what we're doing, and it's working nicely...

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

Heroku now supports ElasticSearch with the Bonsai add on. 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. No need for an EC2 instance - you only pay for the cost of S3 data which is much less - mainly IO transactions. It uses the ElasticSearch S3 gateway (persistence mechanism).

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 ). 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. 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. 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. 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. 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. Performance tests compared to an EC2 cluster + Tire (Rails gem for ElasticSearch) showed that the Heroku/Play approach performed faster searches.

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.

这是我第一次看到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. You need to wait for an Add-on or host it somewhere else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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