https://intercityup.com/blog/installing-elasticsearch-mac-os-x-10-9-mavericks-development/
point $JAVA_HOME to the Java installation path in your .bash_profile:
export JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
brew install elasticsearch
And start elasticsearch with:
elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
https://shellycloud.com/blog/2013/10/adding-search-and-autocomplete-to-a-rails-app-with-elasticsearch
# Gemfile
gem "searchkick"
After running
bundle install
, we can configure the Book model to be searchable:# app/models/book.rb
class Book < ActiveRecord::Base
searchkick
# ...
end
Next, we need to build the index for the Book class so that the books we already have in the database will be added to Elasticsearch. When new records are created rebuilding isn't necessary, but you have to do it whenever you change the
searchkick
method in your model:rake searchkick:reindex CLASS=Book
https://github.com/ankane/searchkick
Deployment
Searchkick usesENV["ELASTICSEARCH_URL"]
for the Elasticsearch server. This defaults tohttp://localhost:9200
.Heroku
# SearchBox heroku addons:add searchbox:starter heroku config:add ELASTICSEARCH_URL=`heroku config:get SEARCHBOX_URL` # Bonsai heroku addons:add bonsai heroku config:add ELASTICSEARCH_URL=`heroku config:get BONSAI_URL` # Found heroku addons:add foundelasticsearch heroku config:add ELASTICSEARCH_URL=`heroku config:get FOUNDELASTICSEARCH_URL`Then deploy and reindex:heroku run rake searchkick:reindex CLASS=MODEL
沒有留言:
張貼留言