Integrate Elasticsearch in ruby on rails

Initial requirement:-You need to install elasticksearch library into your system

sudo apt-get update
sudo 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.deb
sudo dpkg -i elasticsearch-1.1.1.deb
sudo service elasticsearch start #curl http://localhost:9200
Install 3 gems

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').records
end
In the lib/tasks/elasticsearch.rake file:
require 'elasticsearch/rails/tasks/import'
Thanks

Comments

Popular Posts

How to pass hash in Postman

nginx: unrecognized service

Bootstrap Select Picker append add new item if search not exist

Reading Excel Sheets using "Roo" gem in ruby on rails

Add CORS to Nginx on AWS Elastic Beanstalk

Enable gzip compression on Elastic Beanstalk with nginx

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Get video duration by URL in Ruby on Rails

site-enables nginx setting in ruby in rails