A Rails app that uses Tire to interact with Elastic Search deployed on Cloud Foundry
Ruby JavaScript CoffeeScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Rails app that uses Tire to interact with Elastic Search deployed on Cloud Foundry. This app was originally created by running the "rails new searchapp" command explained under "ActiveModel Integration" in the Tire README.

Setting up Elastic Search

This app connects to an instance of Elastic Search running on Cloud Foundry. Follow these instructions to deploy Elastic Search as a standalone application:

  • Download and unzip the latest stable release of Elastic Search
  • Modify config/elasticsearch.yml to use Cloud Foundry-provided host and port
# ElasticSearch, by default, binds itself to the address, and listens
# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
# communication. (the range means that if the port is busy, it will automatically
# try the next port).

# Set the bind address specifically (IPv4 or IPv6):
network.bind_host: ${VCAP_APP_HOST}

# Set the address other nodes will use to communicate with this node. If not
# set, it is automatically derived. It must point to an actual IP address.
# network.publish_host:

# Set both 'bind_host' and 'publish_host':
network.host: ${VCAP_APP_HOST}

# Set a custom port for the node to node communication (9300 by default):
# transport.tcp.port: 9300

# Enable compression for all communication between nodes (disabled by default):
# transport.tcp.compress: true

# Set a custom port to listen for HTTP traffic:
http.port: ${VCAP_APP_PORT}
  • Deploy Elastic Search to Cloud Foundry using the provided manifest. You may need to modify the manifest to generate a unique URL.
cd elasticsearch-0.19.2
cp rails-elastic-search/elastic-search-manifest.yml .
vmc push --manifest=elastic-search-manifest.yml

You should now be able to direct REST requests to myelasticsearch.cloudfoundry.com

Deploying rails-elastic-search to Cloud Foundry

Cloud Foundry runs your Rails app in production mode, therefore you need to precompile assets prior to deploying:

rake assets:precompile

You also need to update the Tire configuration to point to the URL you've assigned to Elastic Search. Edit the following line in config/environments/production.rb:

Tire::Configuration.url "http://myelasticsearch.cloudfoundry.com"

To deploy the application to Cloud Foundry, simply use the provided manifest.yml file. You need only to provide the application with a name and URL.

vmc push
Would you like to deploy from the current directory? [Yn]:
Application Name: searchapp
Application Deployed URL [searchapp.cloudfoundry.com]:

Seeding the database

Use the vmc rails-console to seed the database once your application is deployed to Cloud Foundry. This will add some example articles to the app's database as well as elasticsearch (through the use of Tire). Note that memory used while running the console contributes to your overall application memory limit.

vmc rails-console searchapp
Deploying tunnel application 'caldecott'.
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (1K): OK
Push Status: OK
Staging Application 'caldecott': OK
Starting Application 'caldecott': OK
Connecting to 'searchapp' console: OK

irb():001:0> `rake db:seed`
irb():002:0> exit