Integrate Elasticsearch in ruby on rails
Initial requirement:-You need to install elasticksearch library into your system
Install 3 gemssudo apt-get updatesudo apt-get install openjdk-7-jre-headless -y ### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below # NEW WAY / EASY WAY wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.debsudo dpkg -i elasticsearch-1.1.1.debsudo service elasticsearch start #curl http://localhost:9200
gem "elasticsearch", git: "git://github.com/elasticsearch/elasticsearch-ruby.git"
gem "elasticsearch-model", git: "git://github.com/elasticsearch/elasticsearch-rails.git"
gem "elasticsearch-rails", git: "git://github.com/elasticsearch/elasticsearch-rails.git"
In model:-
require 'elasticsearch/model'
class Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
Article.import
In controller:-
def search@articles = Article.search('foobar').recordsend
In thelib/tasks/elasticsearch.rake
file:require 'elasticsearch/rails/tasks/import'
Thanks
Comments
Post a Comment