Features
Distributed and Highly Available Search Engine
Each index is fully sharded with a configurable number of shards
Each shard can have one or more replicas
Read / Search operations performed on either one of the replica
shard
Multi Tenant with Multi Types
Various set of APIs
Features
Document Oriented
No need for upfront schema definition
(Near) Real Time Search
Per-Operation Persistence
Single document level operations are atomic, consistent, isolated
and durable
Features
Built on top of Lucene
Each shard is a fully functional Lucene index
All the power of Lucene easily exposed through simple
configuration / plugins
Independent of file format
Open Source under Apache 2 License
Setting up ElasticSearch w/
Ruby
The ElasticSearch is not ruby specific so 'tire' gem helps ruby
based projects to communicate with ElasticSearch
'tire' gem
https://github.com/karmi/retire
We then need to require following libraries
require 'rubygems'
require 'tire'
Indexing Records
Indexing includes both “Create” and “Update” in CRUD.
In order to make index request for new JSON object, we pass
the following URL
http://localhost:<port>/<index>/<type>/[<id>].
Indexing
Creating an index
curl -XPUT "http://localhost:9200/movies/movie/1" -d'
{
"title": "The Godfather",
"director": "Francis Ford Coppola",
"year": 1972
}'
Indexing Response
After executing the request, we get the following response
{
}
“ok”:
“_index”:
“_type”:
“_id”:
“_version”:
true,
“movies”,
“movie”,
“1”,
1
Demo Application
Demo Application by karmi
$ rails new searchapp -m
https://raw.github.com/karmi/tire/master/exam les/railsapplication-template.rb
Demo: Search App - Model
Model
include Tire::Model::Search
include Tire::Model::Callbacks
These two 'tire' models allow your rails application to use tire
gem for searching purposes
Demo: Search App
- Controller
Controller
@articles = Article.tire.search params[:query]
This line in your search method helps to search using tire gem