SlideShare une entreprise Scribd logo
1  sur  23
ElasticSearch



Presented by:
Abuzar Hasan
Arkhitech <http://www.arkhitech.com>
History


Shay Baron




Compass in 2004
ElasticSearch in 2010






Written in Java
Cross-platform
Distributed
Users








StumbleUpon
Mozilla
Github

Foursquare
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 Elastic Search


Download ElasticSearch (CentOS)
sudo yum install elasticsearch




Start ElasticSearch Server


elasticsearch -f -D
es.config=/usr/local/Cellar/elasticsearch/0.18.5/config/elasticsear
ch.yml
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
Retrieving Index


Retrieving the index


curl -XGET "http://localhost:9200/movies/movie/1" -d''
Retrieve Index Response
{














“_index”:
“_type”:
“_id”:
“_version”:
“exists”:
“_source”:










}

}

“movies”,
“movie”,
“1”,
1,
true,
{

"title": "The Godfather",
"director": "Francis Ford Coppola",
"year": 1972
Delete Index


Deleting the index


curl -XDELETE "http://localhost:9200/movies/movie/1" -d''
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
Demo: Search App - View


View









<%= form_tag search_articles_path, method: :get do %>
<%= text_field_tag :q, params[:query] %>
<%= submit_tag :search %>
<% end %>
Demo: Search App - Index


Create an index


















Tire.index 'articles' do
delete
create
store :title => 'One', :tags => ['ruby']
store :title => 'Two', :tags => ['ruby', 'python']
store :title => 'Three', :tags => ['java']
store :title => 'Four', :tags => ['ruby', 'php']
refresh
end
Demo: Search App - Index


For custom mapping
Tire.index 'articles' do


delete
create :mappings => {
:article => {
:properties => {
:id
=> { :type => 'string', :index => 'not_analyzed', :include_in_all => false },
:title => { :type => 'string', :boost => 2.0, :analyzer => 'snowball' },
:tags => { :type => 'string', :analyzer => 'keyword' },
:content => { :type => 'string', :analyzer => 'snowball' }
}
}





















}




end
Demo: Search App – Bulk
Indexing




For indexing large amount of data
articles = [












{ :id => '1', :type => 'article', :title => 'one', :tags => ['ruby'] },
{ :id => '2', :type => 'article', :title => 'two', :tags => ['ruby', 'python'] },
{ :id => '3', :type => 'article', :title => 'three', :tags => ['java'] },
{ :id => '4', :type => 'article', :title => 'four', :tags => ['ruby', 'php'] }

]
Use Import






Tire.index 'articles' do
import articles
end
Displaying Facets


For displaying facets
s.results.facets['global-tags']['terms'].each do |f|








puts "#{f['term'].ljust(10)} #{f['count']}"

end

Output








ruby
python
php
java

3
1
1
1
References
• https://github.com/karmi/retire
• http://railscasts.com/episodes/306-elasticsearch-part1

QUESTIONS?

Contenu connexe

Tendances

CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIs
anthony_putignano
 
Enterprise search in_drupal_pub
Enterprise search in_drupal_pubEnterprise search in_drupal_pub
Enterprise search in_drupal_pub
dstuartnz
 
Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr Developers
Erik Hatcher
 

Tendances (20)

Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
เกี่ยวกับ Apache solr 4.0
เกี่ยวกับ Apache solr 4.0เกี่ยวกับ Apache solr 4.0
เกี่ยวกับ Apache solr 4.0
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
 
Cusomizing Burp Suite - Getting the Most out of Burp Extensions
Cusomizing Burp Suite - Getting the Most out of Burp ExtensionsCusomizing Burp Suite - Getting the Most out of Burp Extensions
Cusomizing Burp Suite - Getting the Most out of Burp Extensions
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIs
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Rails3 changesets
Rails3 changesetsRails3 changesets
Rails3 changesets
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIs
 
Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr Developers
 
ActionBar and Holo in Android 2+
ActionBar and Holo in Android 2+ActionBar and Holo in Android 2+
ActionBar and Holo in Android 2+
 
REST Easy with Django-Rest-Framework
REST Easy with Django-Rest-FrameworkREST Easy with Django-Rest-Framework
REST Easy with Django-Rest-Framework
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
 
Enterprise search in_drupal_pub
Enterprise search in_drupal_pubEnterprise search in_drupal_pub
Enterprise search in_drupal_pub
 
Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr Developers
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful Code
 

En vedette

Mentoring I
Mentoring IMentoring I
Mentoring I
shendin
 
Xaneiro 2015
Xaneiro 2015Xaneiro 2015
Xaneiro 2015
iesasorey
 
Scan, Focus, Act
Scan, Focus, ActScan, Focus, Act
Scan, Focus, Act
easleyme
 
As noções de erro e fracasso no contexto escolar: algumas considerações preli...
As noções de erro e fracasso no contexto escolar: algumas considerações preli...As noções de erro e fracasso no contexto escolar: algumas considerações preli...
As noções de erro e fracasso no contexto escolar: algumas considerações preli...
Jefjac
 

En vedette (20)

QMiner - Data analytics platform for processing large-scale real-time stream...
 QMiner - Data analytics platform for processing large-scale real-time stream... QMiner - Data analytics platform for processing large-scale real-time stream...
QMiner - Data analytics platform for processing large-scale real-time stream...
 
Hi, today i present you five famous
Hi, today i present you five famousHi, today i present you five famous
Hi, today i present you five famous
 
Mentoring I
Mentoring IMentoring I
Mentoring I
 
Factura
FacturaFactura
Factura
 
碳酸鈉81027
碳酸鈉81027碳酸鈉81027
碳酸鈉81027
 
Factors that influence path to purchase
Factors that influence path to purchaseFactors that influence path to purchase
Factors that influence path to purchase
 
Xaneiro 2015
Xaneiro 2015Xaneiro 2015
Xaneiro 2015
 
Xander santiago 7 b
Xander santiago 7 bXander santiago 7 b
Xander santiago 7 b
 
Presentación sobre Diabetes
Presentación sobre DiabetesPresentación sobre Diabetes
Presentación sobre Diabetes
 
HP LaserJet Pro P1606dn – CE278A Toner Replacement
HP LaserJet Pro P1606dn – CE278A Toner ReplacementHP LaserJet Pro P1606dn – CE278A Toner Replacement
HP LaserJet Pro P1606dn – CE278A Toner Replacement
 
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
 
Why Tablets? | 2011
Why Tablets? | 2011Why Tablets? | 2011
Why Tablets? | 2011
 
HAPPYWEEK 202 - 2017.01.16.
HAPPYWEEK 202 - 2017.01.16.HAPPYWEEK 202 - 2017.01.16.
HAPPYWEEK 202 - 2017.01.16.
 
Чингэлтэй дүүргийн 9 дүгээр хороо Дэнжийн 1000-ийн дахин төлөвлөлт
Чингэлтэй дүүргийн 9 дүгээр хороо Дэнжийн 1000-ийн дахин төлөвлөлтЧингэлтэй дүүргийн 9 дүгээр хороо Дэнжийн 1000-ийн дахин төлөвлөлт
Чингэлтэй дүүргийн 9 дүгээр хороо Дэнжийн 1000-ийн дахин төлөвлөлт
 
Scan, Focus, Act
Scan, Focus, ActScan, Focus, Act
Scan, Focus, Act
 
As noções de erro e fracasso no contexto escolar: algumas considerações preli...
As noções de erro e fracasso no contexto escolar: algumas considerações preli...As noções de erro e fracasso no contexto escolar: algumas considerações preli...
As noções de erro e fracasso no contexto escolar: algumas considerações preli...
 
Avaliação
AvaliaçãoAvaliação
Avaliação
 
12 Questions to Ask When Making a Content Marketing Technology Decision
12 Questions to Ask When Making a Content Marketing Technology Decision12 Questions to Ask When Making a Content Marketing Technology Decision
12 Questions to Ask When Making a Content Marketing Technology Decision
 
The Science of Gratitude
The Science of Gratitude The Science of Gratitude
The Science of Gratitude
 
4 Model Kepribadian ( D I S C)
4 Model Kepribadian ( D I S C)4 Model Kepribadian ( D I S C)
4 Model Kepribadian ( D I S C)
 

Similaire à Introduction to ElasticSearch

Search Engine Capabilities - Apache Solr(Lucene)
Search Engine Capabilities - Apache Solr(Lucene)Search Engine Capabilities - Apache Solr(Lucene)
Search Engine Capabilities - Apache Solr(Lucene)
Manish kumar
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s ElasticsearchAko prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
bart-sk
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
Erik Hatcher
 

Similaire à Introduction to ElasticSearch (20)

Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of Lucene
 
Apache Lucene Searching The Web
Apache Lucene Searching The WebApache Lucene Searching The Web
Apache Lucene Searching The Web
 
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
Apache Lucene: Searching the Web and Everything Else (Jazoon07)Apache Lucene: Searching the Web and Everything Else (Jazoon07)
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Prototyping applications with heroku and elasticsearch
 Prototyping applications with heroku and elasticsearch Prototyping applications with heroku and elasticsearch
Prototyping applications with heroku and elasticsearch
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
 
Search Engine Capabilities - Apache Solr(Lucene)
Search Engine Capabilities - Apache Solr(Lucene)Search Engine Capabilities - Apache Solr(Lucene)
Search Engine Capabilities - Apache Solr(Lucene)
 
[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
[2 d1] elasticsearch 성능 최적화
[2 d1] elasticsearch 성능 최적화[2 d1] elasticsearch 성능 최적화
[2 d1] elasticsearch 성능 최적화
 
Tips for Angular Applications
Tips for Angular ApplicationsTips for Angular Applications
Tips for Angular Applications
 
Adding High Performance Search to your Grails App
Adding High Performance Search to your Grails AppAdding High Performance Search to your Grails App
Adding High Performance Search to your Grails App
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s ElasticsearchAko prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Using Thinking Sphinx with rails
Using Thinking Sphinx with railsUsing Thinking Sphinx with rails
Using Thinking Sphinx with rails
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
Android search
Android searchAndroid search
Android search
 
Android search
Android searchAndroid search
Android search
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Introduction to ElasticSearch

  • 2. History  Shay Baron   Compass in 2004 ElasticSearch in 2010    Written in Java Cross-platform Distributed
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. Setting Up Elastic Search  Download ElasticSearch (CentOS) sudo yum install elasticsearch   Start ElasticSearch Server  elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.18.5/config/elasticsear ch.yml
  • 8. 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'
  • 9. 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>].
  • 10. Indexing   Creating an index curl -XPUT "http://localhost:9200/movies/movie/1" -d' {  "title": "The Godfather", "director": "Francis Ford Coppola", "year": 1972     }'
  • 11. Indexing Response  After executing the request, we get the following response {        } “ok”: “_index”: “_type”: “_id”: “_version”: true, “movies”, “movie”, “1”, 1
  • 12. Retrieving Index  Retrieving the index  curl -XGET "http://localhost:9200/movies/movie/1" -d''
  • 14. Delete Index  Deleting the index  curl -XDELETE "http://localhost:9200/movies/movie/1" -d''
  • 15. Demo Application  Demo Application by karmi  $ rails new searchapp -m https://raw.github.com/karmi/tire/master/exam les/railsapplication-template.rb
  • 16. 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
  • 17. Demo: Search App - Controller  Controller   @articles = Article.tire.search params[:query] This line in your search method helps to search using tire gem
  • 18. Demo: Search App - View  View     <%= form_tag search_articles_path, method: :get do %> <%= text_field_tag :q, params[:query] %> <%= submit_tag :search %> <% end %>
  • 19. Demo: Search App - Index  Create an index          Tire.index 'articles' do delete create store :title => 'One', :tags => ['ruby'] store :title => 'Two', :tags => ['ruby', 'python'] store :title => 'Three', :tags => ['java'] store :title => 'Four', :tags => ['ruby', 'php'] refresh end
  • 20. Demo: Search App - Index  For custom mapping Tire.index 'articles' do  delete create :mappings => { :article => { :properties => { :id => { :type => 'string', :index => 'not_analyzed', :include_in_all => false }, :title => { :type => 'string', :boost => 2.0, :analyzer => 'snowball' }, :tags => { :type => 'string', :analyzer => 'keyword' }, :content => { :type => 'string', :analyzer => 'snowball' } } }           }   end
  • 21. Demo: Search App – Bulk Indexing   For indexing large amount of data articles = [       { :id => '1', :type => 'article', :title => 'one', :tags => ['ruby'] }, { :id => '2', :type => 'article', :title => 'two', :tags => ['ruby', 'python'] }, { :id => '3', :type => 'article', :title => 'three', :tags => ['java'] }, { :id => '4', :type => 'article', :title => 'four', :tags => ['ruby', 'php'] } ] Use Import    Tire.index 'articles' do import articles end
  • 22. Displaying Facets  For displaying facets s.results.facets['global-tags']['terms'].each do |f|     puts "#{f['term'].ljust(10)} #{f['count']}" end Output     ruby python php java 3 1 1 1