Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhenrixon/3131774 to your computer and use it in GitHub Desktop.
Save mhenrixon/3131774 to your computer and use it in GitHub Desktop.
Configuring Tire to work with Bonsai

Configuring Tire to use the Bonsai ElasticSearch Heroku add-on

gem 'tire', '~> 0.4.1'

Bonsai provisions one ElasticSearch index per application. Tire, however, assumes that each model is using its own index.

Currently the best way to work around this is to set the Tire.configuration.url and the model's index_name manually.

config/initializers/bonsai.rb

if ENV['BONSAI_INDEX_URL']
  Tire.configure do
    url "http://index.bonsai.io"
  end
  BONSAI_INDEX_NAME = ENV['BONSAI_INDEX_URL'][/[^\/]+$/]
else
  app_name = Rails.application.class.parent_name.underscore.dasherize
  app_env = Rails.env
  BONSAI_INDEX_NAME = "#{app_name}-#{app_env}"
end

app/models/article.rb

class Article
  include Tire::Model::Search
  include Tire::Model::Callbacks
  index_name BONSAI_INDEX_NAME
end

Known issues

  • Fixed in Tire 0.4.1 Bulk import uses cluster-level /_bulk handler rather than the index-level _bulk handler, causing bulk imports to fail. Issue 327
  • Multi-model search is not scoped within the index. Issue 322
@nz
Copy link

nz commented Oct 18, 2012

@mhenrixon — fyi, just updated the original gist for some changes deployed today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment