Elasticsearch:Beyond the Railscasts       Scott Hamilton   scott@cabforward.com
What is ElasticSearch?ElasticSearch is a scalable, distributed, cloud-ready, highly-available, full-text search engine and...
Whats so great about       ElasticSearch?1.No configuration to get started.2.RESTful - we all know it and love it3.Schemal...
DistributedArchitecture
What does it have over            Solr?A detailed comparisonhttp://blog.sematext.com/2012/08/23/solr-vs-elasticsearch-part...
Where the railscasts left off... class Post < ActiveRecord::Base   attr_accessible :title, :body, :user_id   belongs_to :u...
Where the railscasts left off...  def self.search(params)    tire.search(page: params[:page], per_page: 3) do      query d...
Where the railscasts left off...<div id="posts">  <% @posts.each do |post| %>    <h2><%= link_to post.title, post %></h2> ...
Where the railscasts left off...class Post < ActiveRecord::Base  attr_accessible :title, :body, :user_id  belongs_to :user...
Cleaning House     mapping do       indexes :id, type: integer, index: :not_analyzed       indexes :title       indexes :b...
Stay In Syncclass User < ActiveRecord::Base  attr_accessible :first_name, :last_name, :bio  has_many :posts  after_save { ...
AnalyzersElastic Search indexes document with tokens extracted from properties. Prefix search is a specific need and ishandl...
Indexing Partial Wordsclass Post < ActiveRecord::Base  attr_accessible :title, :body, :user_id  belongs_to :user  include ...
Indexing Partial Words..............  mapping do    indexes :id, type: integer, index: :not_analyzed    indexes :title    ...
Indexing Partial Words  ...........  def self.search(params)    tire.search(page: params[:page], per_page: 3) do      quer...
Resourceshttp://www.elasticsearch.org/guide/https://github.com/karmi/tirehttps://gist.github.com/3200212http://apidock.com...
That’s all!               Please give me feedbackhttp://speakerrate.com/talks/16501-austin-on-rails-        elasticsearch-...
Elastic tire demo
Upcoming SlideShare
Loading in...5
×

Elastic tire demo

4,093

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,093
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
24
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Elastic tire demo

    1. 1. Elasticsearch:Beyond the Railscasts Scott Hamilton scott@cabforward.com
    2. 2. What is ElasticSearch?ElasticSearch is a scalable, distributed, cloud-ready, highly-available, full-text search engine anddatabase with powerfull aggregation features,communicating by JSON over RESTful HTTP,based on Lucene, written in Java.
    3. 3. Whats so great about ElasticSearch?1.No configuration to get started.2.RESTful - we all know it and love it3.Schemaless JSON datasource4.MultiTenancy - multiple indexes and the ability to search across them5.Settings - each index can have its own settings6.Distributed by nature7.Gateway concept for easy restore and backup
    4. 4. DistributedArchitecture
    5. 5. What does it have over Solr?A detailed comparisonhttp://blog.sematext.com/2012/08/23/solr-vs-elasticsearch-part-1-overview/My Opinion:1.Easier to setup2.Easy to understand3.REST + JSON4.Built for Cloud Computing5.Foundation of Solr with a new approach6.SUPER fast with realtime search
    6. 6. Where the railscasts left off... class Post < ActiveRecord::Base attr_accessible :title, :body, :user_id belongs_to :user include Tire::Model::Search include Tire::Model::Callbacks mapping do indexes :id, type: integer, index: :not_analyzed indexes :title indexes :body indexes :user_full_name, boost: 10 indexes :user_id, type: integer, index: :not_analyzed indexes :created_at, type: date, index: :not_analyzed end
    7. 7. Where the railscasts left off... def self.search(params) tire.search(page: params[:page], per_page: 3) do query do boolean do must { string params[:query], default_operator: "AND" } if params[:query].present? must { range :created_at, lte: Time.zone.now } must { term :user_id, params[:user_id] } if params[:user_id].present? end end sort { by :created_at, "desc" } if params[:query].blank? facet "users" do terms :user_id end end end def to_indexed_json to_json(methods: [:user_full_name]) end def user_full_name user.full_name endend
    8. 8. Where the railscasts left off...<div id="posts"> <% @posts.each do |post| %> <h2><%= link_to post.title, post %></h2> <div class="info"> by <%= post.user_full_name %> on <%= post.created_at.to_time.strftime(%b %d, %Y) %> </div> <div class="body"> <%= post.body %> </div> <% end %></div>
    9. 9. Where the railscasts left off...class Post < ActiveRecord::Base attr_accessible :title, :body, :user_id belongs_to :user include Tire::Model::Search include Tire::Model::Callbacks mapping do indexes :id, type: integer, index: :not_analyzed indexes :title indexes :body indexes :user_full_name, boost: 10 indexes :user_id, type: integer, index: :not_analyzed indexes :created_at, type: date, index: :not_analyzed end def self.search(params) tire.search(page: params[:page], per_page: 3) do query do boolean do must { string params[:query], default_operator: "AND" } ifparams[:query].present? must { range :created_at, lte: Time.zone.now } must { term :user_id, params[:user_id] } if params[:user_id].present? end end
    10. 10. Cleaning House mapping do indexes :id, type: integer, index: :not_analyzed indexes :title indexes :body indexes :user do indexes :full_name, boost: 10 end indexes :user_id, type: integer, index: :not_analyzed indexes :created_at, type: date, index: :not_analyzed end def to_indexed_json to_json(include: {user: { methods: [:full_name] } }) end<div id="posts"> <% @posts.each do |post| %> <h2><%= link_to post.title, post %></h2> <div class="info"> by <%= post.user.full_name %> on <%= post.created_at.to_time.strftime(%b %d, %Y) %> </div> <div class="body"> <%= post.body %> </div> <% end %></div>
    11. 11. Stay In Syncclass User < ActiveRecord::Base attr_accessible :first_name, :last_name, :bio has_many :posts after_save { self.posts.each{ |p| p.tire.update_index } } def full_name "#{self.first_name} #{self.last_name}" endendclass Post < ActiveRecord::Base attr_accessible :title, :body, :user_id belongs_to :user include Tire::Model::Search include Tire::Model::Callbacks mapping do indexes :id, type: integer, index: :not_analyzed indexes :title indexes :body indexes :user do indexes :full_name, boost: 10 end indexes :user_id, type: integer, index: :not_analyzed indexes :created_at, type: date, index: :not_analyzed end
    12. 12. AnalyzersElastic Search indexes document with tokens extracted from properties. Prefix search is a specific need and ishandled with edge ngram, a variant of ngram. Ngram is a group a contiguous letters extracted from a word. Edge ngram is a ngram built from the start or the end of a word. A token filter of type asciifolding that convertsalphabetic, numeric, and symbolic Unicode characters which are not in the first 127 ASCII characters (the “Basic Latin” Unicode block) into their ASCII equivalents, if one exists.
    13. 13. Indexing Partial Wordsclass Post < ActiveRecord::Base attr_accessible :title, :body, :user_id belongs_to :user include Tire::Model::Search include Tire::Model::Callbacks settings analysis: { filter: { front_edge: { type: "edgeNGram", side: "front", max_gram: 8, min_gram: 4 } }, analyzer: { partial_match: { tokenizer: "whitespace", filter: %w{asciifolding lowercase front_edge} }, whole_sort: { tokenizer: keyword, filter: %w{asciifolding lowercase} } } } do ...............
    14. 14. Indexing Partial Words.............. mapping do indexes :id, type: integer, index: :not_analyzed indexes :title indexes :body, type: multi_field, fields: { start: { type: string, analyzer: partial_match, include_in_all: false }, kw: { type: string, analyzer: snowball, include_in_all: false }, sort: { type: string, analyzer: whole_sort, include_in_all: false } } indexes :user do indexes :full_name, boost: 10 end indexes :user_id, type: integer, index: :not_analyzed indexes :created_at, type: date, index: :not_analyzed end.........
    15. 15. Indexing Partial Words ........... def self.search(params) tire.search(page: params[:page], per_page: 3) do query do boolean do must { string "body.start:#{params[:query]} OR body.kw:#{params[:query]} OR #{params[:query]}", default_operator: "AND" } if params[:query].present? must { range :created_at, lte: Time.zone.now } must { term :user_id, params[:user_id] } if params[:user_id].present? end end if params[:query].blank? sort { by :created_at, "desc" } else sort {by body.sort, asc } end facet "users" do terms :user_id end end end def to_indexed_json to_json(include: {user: { methods: [:full_name] } }) endend
    16. 16. Resourceshttp://www.elasticsearch.org/guide/https://github.com/karmi/tirehttps://gist.github.com/3200212http://apidock.com/rails/ActiveRecord/Serialization/to_jsonhttp://blog.socialcast.com/realtime-search-solr-vs-elasticsearch/http://www.elasticsearch.org/blog/2011/02/08/percolator.htmlhttp://en.wikipedia.org/wiki/ElasticSearch#Comparison_to_other_softwarehttps://github.com/karmi/railscasts-episodes/commit/03c45c365d1cc23c27ec67280b0fe315164ab116
    17. 17. That’s all! Please give me feedbackhttp://speakerrate.com/talks/16501-austin-on-rails- elasticsearch-beyond-the-screencasts
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×