Elastic search on Rails

Elastic search is a mirror db with indexes of your existing DB, which is seachable trough JSON API. In order to perform search you will need to have the data synced between your DB and ElasticSerach. This can be done via rivers to pull data from your application or to push data to your ES node via _bulk operations.

But let’s start from beginning:

1.Download Elastic Search deb
cd /usr/share/elasticsearch

 # To install Marvel inside development enviroment
sudo bin/plugin -i elasticsearch/marvel/latest

# In same directory run ES 
bin/elasticsearch -d

#Check if it's working
localhost:9200

Keeping data in sync

The simple way:

class Article
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks
end

More complex way would be:

# 1. Bind callbacks
 after_commit on: [:create] do
  index_document if self.published?
 end

after_commit on: [:update] do
 update_document if self.published?
end

after_commit on: [:destroy] do
  delete_document if self.published?
end

Using async commands – a way to go

Please refer to
https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-     model

JDBC plugin for Elasticsearch

The Java Database Connection (JDBC) plugin allows to fetch data from JDBC sources for indexing into Elasticsearch.

https://github.com/jprante/elasticsearch-river-jdbc

You can setup a script that pulls data from MySQL into ES. You will have to write custom SQL queries to do so.

Marvel Plugin

#Check Marvel plugin
http://any-server-in-cluster:9200/_plugin/marvel/.

Marvel

Java versions

We recommend installing the Java 8 update 20 or later, or Java 7 update 55 or later. Previous versions of Java 7 are known to have bugs that can cause index corruption and data loss.

Hosted solutions

https://qbox.io/

Some references:

http://serverfault.com/questions/386557/how-to-index-mysql-from-elasticsearch