SlideShare a Scribd company logo
elasticsearch
Shifa Khan
github/shifakhan
@findshifa
Why do we need search options?
We need it to make our lives easier
Find stuff that is relevant to us
Find it faster
How do we add seach features to our projects?
Options available:
● Standard Database Query
● Lucene libraries
● Solr
● Sphinx
● Elasticsearch
elasticsearch
. . .
Topics for today!
Full Text Searching
RESTful ES
Elasticsearch in Rails
Advanced features of ES
Note: ES = ElasticSearch
What is elasticsearch?
●Database server
●Implemented with RESTful HTTP/JSON
●Easily scalable (hence the name
elasticsearch)
●Based on Lucene
Features of elasticsearch
●Schema-free
●Real-time
●Easy to extend with a plugin system for new functionality
●Automatic discovery of peers in a cluster
●Failover and replication
●Community support: Multiple clients available in various
languages for easy integration
Tire gem- ruby client available for ActiveModel integration
Terminology
Relational database
Database
Table
Row
Column
Schema
Elasticsearch
Index
Type
Document
Field
Mapping
INDEX
DOC-TYPE
Data Structure
of
Elasticsearch
Inside ES
An Index can have multiple types.
Each type can have multiple
documents.
Each document contains data in
JSON format
DOC-TYPE
INDEX
DOC-TYPE
{..} {..}
Document
INDEX
DOC-TYPE
DOC-TYPE
Searches can also be
performed in multiple
indices
How does elasticsearch work?
Full text searching
●Inverted indexing
●Analysis
FULL TEXT SEARCH
stars shine
sky
stars stars
sky
cloudy
sky
[0] [1] [2]
FULL TEXT SEARCH
stars shine
sky
stars stars
sky
cloudy
sky
WORD LOCATION
stars 0,1
shine 0
sky 0,1,2
cloudy 2
FULL TEXT SEARCH
stars shine
sky
stars stars
sky
cloudy
sky
WORD LOCATION
stars 0,1
shine 0
sky 0,1,2
cloudy 2
FULL TEXT SEARCH
stars shine
sky
stars stars
sky
cloudy
sky
WORD LOCATION POSITION
stars 0 0
1 0,1
shine 0 1
sky 0 2
1 2
2 1
cloudy 2 0
FULL TEXT SEARCH
stars shine
sky
stars stars
sky
cloudy
sky
WORD LOCATION POSITION
stars 0 0
1 0,1
shine 0 1
sky 0 2
1 2
2 1
cloudy 2 0
Are these
positions in
the
document
are
consecutive
?
FULL TEXT SEARCH
stars shine
sky
stars stars
sky
cloudy
sky
WORD LOCATION POSITION
stars 0 0
1 0,1
shine 0 1
sky 0 2
1 2
2 1
cloudy 2 0
We find the
words in
consecutive
positions in
Document 1
ANALYSIS
Analyzing is extracting “terms” from given text.
Processing natural language to make it
computer searchable.
ruby dynamic reflective general purpose oop language combine
syntax inspire perl smalltalk feature first design develop mid 1990
yukihiro matz matsumoto japan
Ruby is a dynamic, reflective, general-purpose OOP language that
combines syntax inspired by Perl with Smalltalk-like features. Ruby
was first designed and developed in the mid-1990s by Yukihiro
"Matz" Matsumoto in Japan.
Stopwords:-removal of words of less
semantic significance
ruby dynamic reflective general purpose oop language combine
syntax inspire perl smalltalk feature first design develop mid 1990
yukihiro matz matsumoto japan
Ruby is a dynamic, reflective, general-purpose OOP language that
combines syntax inspired by Perl with Smalltalk-like features. Ruby
was first designed and developed in the mid-1990s by Yukihiro
"Matz" Matsumoto in Japan.
Lowercase and punctuation marks
ruby dynamic reflective general purpose oop language combine
syntax inspire perl smalltalk feature first design develop mid 1990
yukihiro matz matsumoto japan
Ruby is a dynamic, reflective, general-purpose OOP language that
combines syntax inspired by Perl with Smalltalk-like features. Ruby
was first designed and developed in the mid-1990s by Yukihiro
"Matz" Matsumoto in Japan.
Stemmer:-Deriving root of words
ES Analyzer
●Analyzer:
Consists of one tokenizer and multiple token filters
eg: Whitespace, Snowball,etc
●Tokenizer:
It tokenizes all words. Splits sentences into individual
'terms' . Ngram and EdgeNgram highly useful for
autocomplete feature. Path hierarchy tokenizers.
●Token filter:
Actions on tokenized words, basic lowercase to
phonetic filters and stemmers (available in many
languages)
Popular Analyzers
ES is easy to use. Readymade analyzers for
general usage.
● Snowball – excellent for natural language
Standard tokenizer, with standard filter, lowercase filter, stop
filter, and snowball filter
● Some fancy analyzers: Pattern analyzers
For all the Regular expressions guys out there!
"type": "pattern",
"pattern":"s+"
How do we access Elasticsearch?
How do we access Elasticsearch?
Its RESTful
How do we access Elasticsearch?
Its RESTful
GET POST PUT DELETE
PUT /index/type/id
action?
PUT /index/type/id
where?
PUT /twitter_development/type/id
PUT /twitter_development/type/id
what?
PUT /twitter_development/tweet/id
PUT /twitter_development/tweet/id
which?
PUT /twitter_development/tweet/1
curl -XPUT 'localhost:9200/twitter_development/tweet/1' -d
'{
"tweet" : " Elasticsearch is cool! ",
"name" : "Mr Developer"
}'
curl -XPUT 'localhost:9200/twitter_development/tweet/1' -d
'{
"tweet" : " Elasticsearch is cool! ",
"name" : "Mr Developer"
}'
{
"_index":"twitter_development",
"_type":"tweet",
"_id":"1",
"_version": 1,
"ok":true
}
Similarly,
curl -XGET 'http://localhost:9200/twitter/tweet/1'
Similarly,
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_source" : {
"tweet" : " Elasticsearch is cool! ",
"name" : "Mr Developer"
}
}
curl -XGET 'http://localhost:9200/twitter/tweet/1'
GET /index/_search
GET /index1,index2/_search
GET /ind*/_search
GET /index/type/_search
GET /index/type1,type2/_search
GET /index/type*/_search
GET /_all/type*/_search
Search multiple or
all indices
(databases)
Search all types
(columns)
Also
Similarly,
DELETE
curl -XDELETE 'http://localhost:9200/twitter/tweet/1'
curl -XDELETE 'http://localhost:9200/twitter/'
curl -XDELETE 'http://localhost:9200/twitter/tweet/_query'-d
'{
"term" : { "name" : "developer" }
}'
Delete document
Delete index
Elasticsearch in Rails
ES in your RAILS app
1.Install ES from website. Start service.
2.In your browser check 'http://localhost:9200' for
confirmation.
3.Add 'tire' to Gemfile.
4.In your model file (say 'chwink.rb' ) add-
include Tire::Model::Search
include Tire::Model::Callbacks
5.Run rake environment tire:import CLASS=Chwink
6.In rails console type
Chwink.search(“world”) or Chwink.tire.search(“world”)
7.Results!
Request for Model.search
curl -XGET
'http://localhost:9200/chwink_development/chwink/_search?
-d
'{
"query": {
"query_string": {
"query": "world"
}
}
}'
Autocomplete feature implementation
and
Some examples of readymade and custom
analyzers
Querying
More types of queries and use cases:
●Faceting : Allowing multiple filters
●Pagination : Limiting per page results
●Sort : Sorting results by relevance and scoring
(using Elasticsearch's scoring algorithm)
Advanced features of Elasticsearch
USP of Elasticsearch
BIG! Data Analysis in Real Time
Automatic discovery of peers in a cluster
Failover and replication
Elasticsearch Basics
A1 B1
C1 A2
A3 B2
B2 B1
A3 A1
A2 B2
A2 A3
A2 B1
A1 B2
Automatic Discovery
Module
Node 1 Node 2 Node 3
Shard Replica
A1 B2
B1 A2
C1 B2
A2
A3 B1
A1 B2
A3 B1
A3 A2
B1
B2 A1
Node 1 Node 2 Node 3 Node 4
Automatic Discovery
Module
When a new node
is added...
For each index you can specify:
● Number of shards
– Each index has fixed number of shards
– Shards improve indexing performance
● Number of replicas
– Each shard can have 0-many replicas, can be
changed dynamically
– Replicas improve search performance
High Availability
Tips
●Make sure you make separate indices for test and
development environment
Eg: Add index_name "Chwink_#{Rails.env}" to your model
file
●During tests whenever you save an object make sure you
add : Chwink.tire.index.refresh after each test case.
●Make sure you delete and recreate the index after tests.
Eg: You can add this to your Rspec configuration file
config.after(:each) do
Chwink.tire.Chwink_test.delete
Chwink.tire.create_elasticsearch_index
end
●Debug using log files :
Add to Tire config file: logger "tire_#{Rails.env}.log"
Room for exploration...
Big Desk plugin!
Plug-in for analysis of your search data!
Room for exploration...
Big Desk plugin!
Plug-in for analysis of your search data!
Room for exploration...
Big Desk plugin!
Plug-in for analysis of your search data!
Now you can go ahead and start exploring
Elasticsearch for yourself!!
Thank you!
Questions are welcome!

More Related Content

PPTX
ElasticSearch - DevNexus Atlanta - 2014
PDF
ElasticSearch in action
KEY
Elasticsearch - Devoxx France 2012 - English version
PDF
Workshop: Learning Elasticsearch
ODP
Cool bonsai cool - an introduction to ElasticSearch
PPT
Solr and Elasticsearch, a performance study
PPTX
ElasticSearch in Production: lessons learned
PDF
Intro to Elasticsearch
ElasticSearch - DevNexus Atlanta - 2014
ElasticSearch in action
Elasticsearch - Devoxx France 2012 - English version
Workshop: Learning Elasticsearch
Cool bonsai cool - an introduction to ElasticSearch
Solr and Elasticsearch, a performance study
ElasticSearch in Production: lessons learned
Intro to Elasticsearch

What's hot (20)

PPTX
Battle of the giants: Apache Solr vs ElasticSearch
PDF
Your Data, Your Search, ElasticSearch (EURUKO 2011)
PPTX
An Introduction to Elastic Search.
PPTX
Battle of the Giants - Apache Solr vs. Elasticsearch (ApacheCon)
PPTX
ElasticSearch AJUG 2013
PDF
Introduction to Elasticsearch
PDF
Elasticsearch: You know, for search! and more!
PPT
Solr vs ElasticSearch
PDF
Managing Your Content with Elasticsearch
PPTX
Elasticsearch - DevNexus 2015
PPTX
Introduction to Elasticsearch with basics of Lucene
PDF
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
PDF
Elastic Search
PDF
Introduction to Elasticsearch
PPTX
Intro to elasticsearch
PPTX
Battle of the Giants round 2
PDF
Elasticsearch quick Intro (English)
PPTX
Elastic search Walkthrough
ODP
Elastic search
PPTX
The ultimate guide for Elasticsearch plugins
Battle of the giants: Apache Solr vs ElasticSearch
Your Data, Your Search, ElasticSearch (EURUKO 2011)
An Introduction to Elastic Search.
Battle of the Giants - Apache Solr vs. Elasticsearch (ApacheCon)
ElasticSearch AJUG 2013
Introduction to Elasticsearch
Elasticsearch: You know, for search! and more!
Solr vs ElasticSearch
Managing Your Content with Elasticsearch
Elasticsearch - DevNexus 2015
Introduction to Elasticsearch with basics of Lucene
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
Elastic Search
Introduction to Elasticsearch
Intro to elasticsearch
Battle of the Giants round 2
Elasticsearch quick Intro (English)
Elastic search Walkthrough
Elastic search
The ultimate guide for Elasticsearch plugins
Ad

Viewers also liked (20)

PDF
Isomorphic js - React in Rails
PPS
Montevideo que-linda-que-sos-
PPT
Regalo Muebles y Más...
PDF
Pfarrbrief "Miteinander", Ostern 2011
PDF
Nbscore. Nuevo negocio en las agencias de medios. Grupo Consultores
PDF
IndigoBook
PDF
Los adolescentes y las redes sociales
PPT
“Actitud digital en el nuevo paradigma educativo” - Jornada Menores y disposi...
PPT
Presentacion curso narracion deportiva por sporticus
PPTX
Ruby OOP: Objects over Classes
PDF
Ruby's Object Model: Metaprogramming and other Magic
PDF
Unic - Hinter den Kulissen des Multichannel Commerce
PDF
Refrigerio inicial cajamarca
PPTX
Elasticsearch Introduction
PDF
Certificación de Sistemas de Gestión. Calidad de Servicio
PPT
Sociedad Glaucoma2007
PPT
Rosario Ruiz-'CHARLA RH ELECTRONICO_SMP
ODP
An Introduction to PC-Lint
Isomorphic js - React in Rails
Montevideo que-linda-que-sos-
Regalo Muebles y Más...
Pfarrbrief "Miteinander", Ostern 2011
Nbscore. Nuevo negocio en las agencias de medios. Grupo Consultores
IndigoBook
Los adolescentes y las redes sociales
“Actitud digital en el nuevo paradigma educativo” - Jornada Menores y disposi...
Presentacion curso narracion deportiva por sporticus
Ruby OOP: Objects over Classes
Ruby's Object Model: Metaprogramming and other Magic
Unic - Hinter den Kulissen des Multichannel Commerce
Refrigerio inicial cajamarca
Elasticsearch Introduction
Certificación de Sistemas de Gestión. Calidad de Servicio
Sociedad Glaucoma2007
Rosario Ruiz-'CHARLA RH ELECTRONICO_SMP
An Introduction to PC-Lint
Ad

Similar to Elasticsearch Basics (20)

ODP
Elasticsearch for beginners
PDF
Using elasticsearch with rails
PPTX
ElasticSearch Basic Introduction
PPTX
Elastic pivorak
PDF
Elasticsearch And Ruby [RuPy2012]
PPTX
ElasticSearch for .NET Developers
PPT
How ElasticSearch lives in my DevOps life
PDF
Mastering ElasticSearch with Ruby and Tire
PPTX
Elasticsearch, Logstash, Kibana. Cool search, analytics, data mining and more...
PDF
Introduction to Elasticsearch
PDF
Elasticsearch and Spark
PPTX
Introduction to Elasticsearch
PPTX
Elasticsearch
PPTX
Elastic search overview
PPTX
Elasticsearch
PDF
ElasticSearch
PDF
Elasticsearch Introduction at BigData meetup
PPTX
Elasticsearch an overview
PDF
Elasticsearch, a distributed search engine with real-time analytics
PPTX
Solr vs. Elasticsearch - Case by Case
Elasticsearch for beginners
Using elasticsearch with rails
ElasticSearch Basic Introduction
Elastic pivorak
Elasticsearch And Ruby [RuPy2012]
ElasticSearch for .NET Developers
How ElasticSearch lives in my DevOps life
Mastering ElasticSearch with Ruby and Tire
Elasticsearch, Logstash, Kibana. Cool search, analytics, data mining and more...
Introduction to Elasticsearch
Elasticsearch and Spark
Introduction to Elasticsearch
Elasticsearch
Elastic search overview
Elasticsearch
ElasticSearch
Elasticsearch Introduction at BigData meetup
Elasticsearch an overview
Elasticsearch, a distributed search engine with real-time analytics
Solr vs. Elasticsearch - Case by Case

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Modernizing your data center with Dell and AMD
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced IT Governance
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Monthly Chronicles - July 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Modernizing your data center with Dell and AMD
Advanced Soft Computing BINUS July 2025.pdf
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Electronic commerce courselecture one. Pdf
Advanced IT Governance
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)

Elasticsearch Basics