SlideShare a Scribd company logo
1 of 42
Download to read offline
Mastering
ElasticSearch w/ Ruby
(+ Tire)
Luca Bonmassar, Gild

RubyConf 2013

Tuesday, 5 November 13
Who am I?
I’m Luca Bonmassar (@openmosix)
# 31
# Italian living in San Francisco (and Stockholm)
I work at Gild

I love building products
[for fun, profit and boredom]

Tuesday, 5 November 13
Search use case

You’re building a product
User generated content
Let (other) users find or discover this content

Tuesday, 5 November 13
Search is
NOT easy

It usually starts as

but then you want to support AND, OR, NOT,
double quotes on multiple fields so

and then it goes like

Tuesday, 5 November 13
And so it
goes...

Tuesday, 5 November 13
Agenda
Let’s define a “pet project”
Boilerplate (download, install, scaffold,
config, bla bla bla, yadda, yadda, yadda)
Build a website w/ simple search
Build a more advanced search
What next (homework)

Tuesday, 5 November 13
Project!
(for fun and
no profit)

Tuesday, 5 November 13
Project:
build a full textsearch for
RubyGems.org

Tuesday, 5 November 13
RubyGems
Search
Architecture

RubyGems.org

Web Spider

Elastic Search

Rails App (Tire)

Tuesday, 5 November 13

MongoDB
RubyGems
crawler

github.com/openmosix/rubygems-crawler
1. Download all ruby gem names from
https://rubygems.org/gems
2. Use gems API to download each gem
info: read JSON - write JSON (MongoDB)

Tuesday, 5 November 13
RubyGems
Crawler II

Tuesday, 5 November 13
RubyGems
Search v1

Tuesday, 5 November 13

Code:
github.com/openmosix/rubygems-search
Spoiler: http://rubyconf.bonmassar.it
ElasticSearch

Tuesday, 5 November 13
ElasticSearch
II

Open source search+analytics engine
Distributed
[near] Realtime search
Multi tenant
Built on Apache Lucene
REST APIs
JSON documents

Tuesday, 5 November 13
ElasticSearch
III

1. Download / set up a ES cluster
2. Define settings and data mapping (opt)
3. Index Data
4. Query Index

MongoDB

Elastic Search
{
	
  	
  "ok"	
  :	
  true,
	
  	
  "status"	
  :	
  200,
	
  	
  "version"	
  :	
  {
	
  	
  	
  	
  "number"	
  :	
  "0.90.5",
	
  	
  	
  	
  "lucene_version"	
  :	
  "4.4"
	
  	
  },
	
  	
  "tagline"	
  :	
  "You	
  Know,	
  for	
  Search"
}
Tuesday, 5 November 13

curl	
  -­‐X	
  GET	
  'h.p://localhost:9200/
ruby_gems/_search?from=0&size=25&pre.y'

> Curl
ES
download +
setup

> wget http://download.elasticsearch.org/
elasticsearch/elasticsearch/
elasticsearch-0.90.6.tar.gz
> tar zxvf elasticsearch-0.90.6.tar.gz
> sudo mv elasticsearch-0.90.6 /usr/local/

Hint #1: you need Java
Hint #2: you need Oracle Java

Tuesday, 5 November 13
ES config

> ls elasticsearch-0.90.6/config/
Logging.yml: where to log, how much to log
Elasticsearch.yml: all server config. Defines:
Name of the cluster (change it!!!)
Node parameters (master/slave, store data/router)
Sharing and # replicas
Paths
Plugins
Memory (JVM, heap, memory locking)
Network config
“Gateway” (cluster backup)
Recovery
Discovery
Slow log + GC log

Default options are good enough for dev env
Tuesday, 5 November 13
ES boot +
test

Start: bin/elasticsearch
Test: curl http://localhost:9200/
{
"ok" : true,
"status" : 200,
"name" : "Iron Fist",
"version" : {
"number" : "0.90.6",
"lucene_version" : "4.5.1"
},
"tagline" : "You Know, for Search"
}

Stop: curl -XPOST 'http://localhost:9200/
_shutdown'
{"cluster_name":"elasticsearch","nodes":
{"jm2Z3J4dSzebjJ7Px2fAJg":{"name":"Iron Fist"}}}

Tuesday, 5 November 13
Profit
(you are now an
ElasticSearch
expert - go and
tell the world)

Tuesday, 5 November 13
ElasticSearch
operations
Create a “RubyGem” Index
Defines a “RubyGem” Index data mapping
Index data
(e.g. upload data from MongoDB to ES
index = POST)
Query (= GET)

Tuesday, 5 November 13
Tire
now Re-Tire ;(
A ruby gem wrapping ElasticSearch REST
APIs into a powerful ruby DSL
ActiveModel integration
Rake tasks and utilities to load and query
ElasticSearch

Tuesday, 5 November 13
Tire setup

cat “gem ‘tire’” > Gemfile && bundle install

> cat config/initializers/elasticsearch.rb
...
Tire::Configuration.url('http://localhost:9200')
Tire.configure { logger "#{Rails.root}/log/elasticsearchqueries.log" } if ENV['ES_LOG']

Tuesday, 5 November 13
Define an
ES index
(with Tire DSL)

Tuesday, 5 November 13
Indexing

Get a record
Convert it to JSON format (to_indexed_json)
Push it to Elastic Search (.update_index)

...under the hood...

Tuesday, 5 November 13
Index
(all data)

Naive (POST on index for each record):

Use bulk updates:

...under the hood...

Tuesday, 5 November 13
Search I

Tuesday, 5 November 13
Search II

Tuesday, 5 November 13
Simple Search

Tuesday, 5 November 13
Highlight
matches

Text

...add some CSS...

Tuesday, 5 November 13
Advanced
Search

Tuesday, 5 November 13
Advanced
Search II

Tuesday, 5 November 13
Advanced
Search III

Tuesday, 5 November 13
Facets

Tuesday, 5 November 13
ES facets

Tuesday, 5 November 13
ES facets
(running)

Tuesday, 5 November 13
Facets - UI

Tuesday, 5 November 13
Bonsai Cool
I

Tuesday, 5 November 13

Search Suggesters (Did you mean... ?)
Bonsai Cool
II

Tuesday, 5 November 13

“Similar to this” (aka “More Like This” API)
Bonsai Cool
III

Tuesday, 5 November 13

Percolate API
Deployment
I

Run your own cluster
Some learnings:
at least 3 nodes
memory profiling / GC
install very good monitoring (github.com/
karmi/elasticsearch-paramedic)
more RAM is (always) better
Check IOPS (if on AWS)

Pros:
Total control
Cheaper (lot cheaper)

Cons:
Can be a nightmare / Require dedicated devop
Tuesday, 5 November 13
Deployment
II

ElasticSearch as a service
http://found.no
http://searchly.com
http://bonsai.io

Pros:
Get cluster up & running in a minute
Focus on dev, not troubleshooting
Professional support

Cons:
Expensive
Can be in the wrong region / hosting provider
Expensive
Did I say expensive?

Tuesday, 5 November 13
Thanks!
Code:
github.com/openmosix/rubygems-search
github.com/openmosix/rubygems-crawler
Demo (will be down by the end of rubyconf):
http://rubyconf.bonmassar.it
Say “hi”:
Luca Bonmassar - luca@gild.com
github.com/openmosix
twitter.com/openmosix
linkedin.com/in/lucabonmassar
Tuesday, 5 November 13

More Related Content

What's hot

Introduction to Pelican
Introduction to PelicanIntroduction to Pelican
Introduction to Pelican
Chengjen Lee
 
Introduction to JCR and Apache Jackrabbi
Introduction to JCR and Apache JackrabbiIntroduction to JCR and Apache Jackrabbi
Introduction to JCR and Apache Jackrabbi
Jukka Zitting
 

What's hot (19)

Creating beautiful puppet modules with puppet-lint
Creating beautiful puppet modules with puppet-lintCreating beautiful puppet modules with puppet-lint
Creating beautiful puppet modules with puppet-lint
 
Introduction to Pelican
Introduction to PelicanIntroduction to Pelican
Introduction to Pelican
 
Containers from scratch
Containers from scratchContainers from scratch
Containers from scratch
 
Custom Live Media Spinning
Custom Live Media SpinningCustom Live Media Spinning
Custom Live Media Spinning
 
Bar Camp Atl3
Bar Camp Atl3Bar Camp Atl3
Bar Camp Atl3
 
Secrets with Ansible
Secrets with AnsibleSecrets with Ansible
Secrets with Ansible
 
Palm Developer Day PhoneGap
Palm Developer Day PhoneGap Palm Developer Day PhoneGap
Palm Developer Day PhoneGap
 
Socket.io
Socket.ioSocket.io
Socket.io
 
Containers in 5... 9 minutes
Containers in 5... 9 minutesContainers in 5... 9 minutes
Containers in 5... 9 minutes
 
Introduction to JCR and Apache Jackrabbi
Introduction to JCR and Apache JackrabbiIntroduction to JCR and Apache Jackrabbi
Introduction to JCR and Apache Jackrabbi
 
Dojo, from scratch to result
Dojo, from scratch to resultDojo, from scratch to result
Dojo, from scratch to result
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
Solaris 11 base box for Vagrant using Packer
Solaris 11 base box for Vagrant using PackerSolaris 11 base box for Vagrant using Packer
Solaris 11 base box for Vagrant using Packer
 
Steam Learn: Composer
Steam Learn: ComposerSteam Learn: Composer
Steam Learn: Composer
 
Squidinstallation
SquidinstallationSquidinstallation
Squidinstallation
 
Javascript intro for MAH
Javascript intro for MAHJavascript intro for MAH
Javascript intro for MAH
 
Postgis setup
Postgis setupPostgis setup
Postgis setup
 
Vagrant - Team Development made easy
Vagrant - Team Development made easyVagrant - Team Development made easy
Vagrant - Team Development made easy
 
Difference between php and node
Difference between php and nodeDifference between php and node
Difference between php and node
 

Similar to Mastering ElasticSearch with Ruby and Tire

Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Murat Yener
 
Advanced_Research_Techniques.pdf
Advanced_Research_Techniques.pdfAdvanced_Research_Techniques.pdf
Advanced_Research_Techniques.pdf
ssuser785ce21
 

Similar to Mastering ElasticSearch with Ruby and Tire (20)

Introduction to Express and Grunt
Introduction to Express and GruntIntroduction to Express and Grunt
Introduction to Express and Grunt
 
elasticsearch basics workshop
elasticsearch basics workshopelasticsearch basics workshop
elasticsearch basics workshop
 
Meet Couch DB
Meet Couch DBMeet Couch DB
Meet Couch DB
 
Front-end development automation with Grunt
Front-end development automation with GruntFront-end development automation with Grunt
Front-end development automation with Grunt
 
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
PHP Conference Argentina 2013 - Independizate de tu departamento IT - Habilid...
 
Ruby 2.0 / Rails 4.0, A selection of new features.
Ruby 2.0 / Rails 4.0, A selection of new features.Ruby 2.0 / Rails 4.0, A selection of new features.
Ruby 2.0 / Rails 4.0, A selection of new features.
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 
R packages
R packagesR packages
R packages
 
Mongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappeMongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappe
 
Embulk, an open-source plugin-based parallel bulk data loader
Embulk, an open-source plugin-based parallel bulk data loaderEmbulk, an open-source plugin-based parallel bulk data loader
Embulk, an open-source plugin-based parallel bulk data loader
 
Symfony2 and MongoDB - MidwestPHP 2013
Symfony2 and MongoDB - MidwestPHP 2013   Symfony2 and MongoDB - MidwestPHP 2013
Symfony2 and MongoDB - MidwestPHP 2013
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
 
I motion
I motionI motion
I motion
 
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4
 
Scaling DevOps
Scaling DevOpsScaling DevOps
Scaling DevOps
 
Expressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.jsExpressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.js
 
Elasticsearch sur Azure : Make sense of your (BIG) data !
Elasticsearch sur Azure : Make sense of your (BIG) data !Elasticsearch sur Azure : Make sense of your (BIG) data !
Elasticsearch sur Azure : Make sense of your (BIG) data !
 
Advanced_Research_Techniques.pdf
Advanced_Research_Techniques.pdfAdvanced_Research_Techniques.pdf
Advanced_Research_Techniques.pdf
 
Approach to find critical vulnerabilities
Approach to find critical vulnerabilitiesApproach to find critical vulnerabilities
Approach to find critical vulnerabilities
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Mastering ElasticSearch with Ruby and Tire