SlideShare a Scribd company logo
1 of 18
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
database with powerfull aggregation features,
communicating by JSON over RESTful HTTP,
based on Lucene, written in Java.
What's so great about
       ElasticSearch?
1.No configuration to get started.
2.RESTful - we all know it and love it
3.Schemaless JSON datasource
4.MultiTenancy - multiple indexes and the ability
 to search across them
5.Settings - each index can have it's own
 settings
6.Distributed by nature
7.Gateway concept for easy restore and backup
Distributed
Architecture
What does it have over
            Solr?
A detailed comparison
http://blog.sematext.com/2012/08/23/solr-vs-
elasticsearch-part-1-overview/
My Opinion:
1.Easier to setup
2.Easy to understand
3.REST + JSON
4.Built for Cloud Computing
5.Foundation of Solr with a new approach
6.SUPER fast with realtime search
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
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
  end
end
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>
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" } 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
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>
Stay In Sync
class 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}"
  end
end

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 do
      indexes :full_name, boost: 10
    end
    indexes :user_id, type: 'integer', index: :not_analyzed
    indexes :created_at, type: 'date', index: :not_analyzed
  end
Analyzers
Elastic Search indexes document with tokens extracted
 from properties. Prefix search is a specific need and is
handled 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 converts
alphabetic, 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.
Indexing Partial Words
class 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
    ...............
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
.........
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] } })
  end
end
Resources
http://www.elasticsearch.org/guide/
https://github.com/karmi/tire
https://gist.github.com/3200212
http://apidock.com/rails/ActiveRecord/Serialization/
to_json
http://blog.socialcast.com/realtime-search-solr-vs-
elasticsearch/
http://www.elasticsearch.org/blog/2011/02/08/
percolator.html
http://en.wikipedia.org/wiki/
ElasticSearch#Comparison_to_other_software
https://github.com/karmi/railscasts-episodes/commit/
03c45c365d1cc23c27ec67280b0fe315164ab116
That’s all!
               Please give me feedback
http://speakerrate.com/talks/16501-austin-on-rails-
        elasticsearch-beyond-the-screencasts

More Related Content

What's hot

Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)Chhom Karath
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法Tomohiro Nishimura
 
Chickenbiryani try
Chickenbiryani tryChickenbiryani try
Chickenbiryani tryadmin15kkr
 
Dropping ACID with MongoDB
Dropping ACID with MongoDBDropping ACID with MongoDB
Dropping ACID with MongoDBkchodorow
 
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Damien Seguy
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsMikhail Egorov
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An AnalysisJustin Finkelstein
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3Jeremy Coates
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010leo lapworth
 

What's hot (18)

Inc
IncInc
Inc
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
Chickenbiryani try
Chickenbiryani tryChickenbiryani try
Chickenbiryani try
 
Dropping ACID with MongoDB
Dropping ACID with MongoDBDropping ACID with MongoDB
Dropping ACID with MongoDB
 
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An Analysis
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
Further Php
Further PhpFurther Php
Further Php
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 

Similar to Elastic tire demo

Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
Finding the right stuff, an intro to Elasticsearch with Ruby/RailsFinding the right stuff, an intro to Elasticsearch with Ruby/Rails
Finding the right stuff, an intro to Elasticsearch with Ruby/RailsMichael Reinsch
 
Introduction to Azure DocumentDB
Introduction to Azure DocumentDBIntroduction to Azure DocumentDB
Introduction to Azure DocumentDBAlex Zyl
 
Elasticsearch first-steps
Elasticsearch first-stepsElasticsearch first-steps
Elasticsearch first-stepsMatteo Moci
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overviewAmit Juneja
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperGiordano Scalzo
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudreyAudrey Lim
 
Finding the right stuff, an intro to Elasticsearch (at Rug::B)
Finding the right stuff, an intro to Elasticsearch (at Rug::B) Finding the right stuff, an intro to Elasticsearch (at Rug::B)
Finding the right stuff, an intro to Elasticsearch (at Rug::B) Michael Reinsch
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchPedro Franceschi
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed versionBruce McPherson
 
Stop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalStop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalBjörn Brala
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In ElasticsearchKnoldus Inc.
 
GHC Participant Training
GHC Participant TrainingGHC Participant Training
GHC Participant TrainingAidIQ
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecordMark Menard
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBUwe Printz
 

Similar to Elastic tire demo (20)

Ams adapters
Ams adaptersAms adapters
Ams adapters
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
Finding the right stuff, an intro to Elasticsearch with Ruby/RailsFinding the right stuff, an intro to Elasticsearch with Ruby/Rails
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
 
Introduction to Azure DocumentDB
Introduction to Azure DocumentDBIntroduction to Azure DocumentDB
Introduction to Azure DocumentDB
 
Elasticsearch first-steps
Elasticsearch first-stepsElasticsearch first-steps
Elasticsearch first-steps
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapper
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
 
Finding the right stuff, an intro to Elasticsearch (at Rug::B)
Finding the right stuff, an intro to Elasticsearch (at Rug::B) Finding the right stuff, an intro to Elasticsearch (at Rug::B)
Finding the right stuff, an intro to Elasticsearch (at Rug::B)
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
Stop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalStop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in Drupal
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In Elasticsearch
 
GHC Participant Training
GHC Participant TrainingGHC Participant Training
GHC Participant Training
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
 
Schema plus
Schema plusSchema plus
Schema plus
 
SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Elastic tire demo

  • 1.
  • 2. Elasticsearch: Beyond the Railscasts Scott Hamilton scott@cabforward.com
  • 3. What is ElasticSearch? ElasticSearch is a scalable, distributed, cloud- ready, highly-available, full-text search engine and database with powerfull aggregation features, communicating by JSON over RESTful HTTP, based on Lucene, written in Java.
  • 4. What's so great about ElasticSearch? 1.No configuration to get started. 2.RESTful - we all know it and love it 3.Schemaless JSON datasource 4.MultiTenancy - multiple indexes and the ability to search across them 5.Settings - each index can have it's own settings 6.Distributed by nature 7.Gateway concept for easy restore and backup
  • 6. What does it have over Solr? A detailed comparison http://blog.sematext.com/2012/08/23/solr-vs- elasticsearch-part-1-overview/ My Opinion: 1.Easier to setup 2.Easy to understand 3.REST + JSON 4.Built for Cloud Computing 5.Foundation of Solr with a new approach 6.SUPER fast with realtime search
  • 7. 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
  • 8. 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 end end
  • 9. 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>
  • 10. 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" } 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
  • 11. 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>
  • 12. Stay In Sync class 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}" end end 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 do indexes :full_name, boost: 10 end indexes :user_id, type: 'integer', index: :not_analyzed indexes :created_at, type: 'date', index: :not_analyzed end
  • 13. Analyzers Elastic Search indexes document with tokens extracted from properties. Prefix search is a specific need and is handled 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 converts alphabetic, 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.
  • 14. Indexing Partial Words class 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 ...............
  • 15. 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 .........
  • 16. 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] } }) end end
  • 18. That’s all! Please give me feedback http://speakerrate.com/talks/16501-austin-on-rails- elasticsearch-beyond-the-screencasts

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n