Kyle Decot
Kyle Decot

Reputation: 20815

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!

Upvotes: 13

Views: 13110

Answers (5)

Tom Carchrae
Tom Carchrae

Reputation: 6486

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.

Upvotes: 3

Ryan Long
Ryan Long

Reputation: 661

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/

Upvotes: 15

Scott
Scott

Reputation: 977

Heroku now supports ElasticSearch with the Bonsai add on. https://devcenter.heroku.com/articles/bonsai

Upvotes: 13

Mihai A
Mihai A

Reputation: 1473

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.

Upvotes: 0

John Beynon
John Beynon

Reputation: 37507

That was exactly my first thought when I watched the RailsCast but unfortunately it's a java daemon that it runs as which isn't possible on Heroku.

Upvotes: 0

Related Questions