SlideShare a Scribd company logo
“ Terms of Endearment” The ElasticSearch query language explained Clinton Gormley, YAPC::EU 2011 DRTECH @clintongormley
search for : “ DELETE QUERY ”  We can
search for : “ DELETE QUERY ”  and find : “ deleteByQuery ” We can
but you can only find  what is stored in the database
Normalise values  “ deleteByQuery” 'delete' 'by' 'query' 'deletebyquery'
Normalise values  and search terms “ deleteByQuery” “ DELETE QUERY” ' delete ' 'by' ' query ' 'deletebyquery'
Normalise  values  and search terms “ deleteByQuery” “ DELETE QUERY” ' delete ' 'by' ' query ' 'deletebyquery'
Analyse  values  and search terms “ deleteByQuery” “ DELETE QUERY” ' delete ' 'by' ' query ' 'deletebyquery'
What is stored in ElasticSearch?
{ tweet  => "Perl is GREAT!", posted => "2011-08-15", user  => { name  => "Clinton Gormley", email => "drtech@cpan.org", }, tags  => [" perl" ,"opinion"],  posts  => 2, } Document:
{ tweet   => "Perl is GREAT!", posted  => "2011-08-15", user   => { name   => "Clinton Gormley", email  => "drtech@cpan.org", }, tags   => [" perl" ,"opinion"],  posts   => 2, } Fields:
{ tweet  =>  "Perl is GREAT!", posted =>  "2011-08-15", user  =>  { name  =>  "Clinton Gormley", email =>  "drtech@cpan.org", }, tags   =>  [" perl" ,"opinion"],  posts  =>  2, } Values:
{ tweet  => "Perl is GREAT!", posted => "2011-08-15", user  => { name  => "Clinton Gormley", email => "drtech@cpan.org" }, tags  => [" perl" ,"opinion"],  posts  => 2, } Field types: # object # string # date # nested object # string # string # array of enums # integer
{ tweet  => "Perl is GREAT!", posted => "2011-08-15", user   => { name  => "Clinton Gormley", email  => "drtech@cpan.org", }, tags  => [" perl" ,"opinion"],  posts  => 2, } Nested objects flattened:
{ tweet  => "Perl is GREAT!", posted  => "2011-08-15", user.name  => "Clinton Gormley", user.email  => "drtech@cpan.org", tags  => [" perl" ,"opinion"],  posts  => 2, } Nested objects flattened
{ tweet  =>  "Perl is GREAT!", posted  =>  "2011-08-15", user.name  =>  "Clinton Gormley", user.email =>  "drtech@cpan.org", tags  =>  [" perl" ,"opinion"],  posts  =>  2, } Values analyzed into terms
{ tweet  =>  ['perl','great'], posted  =>  [Date(2011-08-15)], user.name  =>  ['clinton','gormley'], user.email =>  ['drtech','cpan.org'], tags  =>  [' perl' ,'opinion'],  posts  =>  [2], } Values analyzed into terms
database table row ⇒  many tables ⇒  many rows ⇒  one schema ⇒  many columns In MySQL
index type document ⇒  many types ⇒  many documents ⇒  one mapping ⇒  many fields In ElasticSearch
Create index with mappings $es-> create_index ( index  => 'twitter', mappings   => { tweet   => { properties  => { title  => { type => 'string' }, created => { type => 'date'  } }  } } );
Add a mapping $es-> put_mapping (  index => 'twitter', type  => ' user ', mapping   => { properties  => { name  => { type => 'string' }, created => { type => 'date'  }, }  } );
Can add to existing mapping
Can add to existing mapping Cannot change mapping for field
Core field types { type  => 'string', }
Core field types { type  => 'string', # byte|short|integer|long|double|float # date, ip addr, geolocation # boolean # binary (as base 64) }
Core field types { type  => 'string', index  => ' analyzed ', # 'Foo Bar'  ⇒  [ 'foo', 'bar' ] }
Core field types { type  => 'string', index  => ' not_analyzed ', # 'Foo Bar'  ⇒  [ 'Foo Bar' ] }
Core field types { type  => 'string', index  => ' no ', # 'Foo Bar'  ⇒  [ ] }
Core field types { type  => 'string', index  => 'analyzed', analyzer  => 'default', }
Core field types { type  => 'string', index  => 'analyzed', index_ analyzer  => 'default', search_ analyzer => 'default', }
Core field types { type  => 'string', index  => 'analyzed', analyzer  => 'default', boost  => 2, }
Core field types { type  => 'string', index  => 'analyzed', analyzer  => 'default', boost  => 2, include_in_all  => 1 |0 }
Standard
Simple
Whitespace
Stop
Keyword Built in analyzers Pattern
Language
Snowball
Custom
The Brown-Cow's Part_No.  #A.BC123-456 joe@bloggs.com keyword: The Brown-Cow's Part_No. #A.BC123-456 joe@bloggs.com whitespace: The, Brown-Cow's, Part_No., #A.BC123-456, joe@bloggs.com simple: the, brown, cow, s, part, no, a, bc, joe, bloggs, com standard: brown, cow's, part_no, a.bc123, 456, joe, bloggs.com snowball (English): brown, cow, part_no, a.bc123, 456, joe, bloggs.com
Token filters Standard
ASCII Folding
Length
Lowercase
NGram
Edge NGram
Porter Stem
Shingle
Stop
Word Delimiter Stemmer
KStem
Snowball
Phonetic
Synonym
Compound Word
Reverse
Elision
Truncate
Unique
Custom Analyzer $c->create_index( index  => 'twitter', settings  => { analysis => { analyzer => { ascii_html => { type  => 'custom', tokenizer  => 'standard', filter  => [ qw( standard lowercase asciifolding stop ) ], char_filter => ['html_strip'] } } }} );
Searching $result = $es->search( index  => 'twitter', type  => 'tweet',  );
Searching $result = $es->search( index  =>  ['twitter','facebook'] , type  =>  ['tweet','post'] ,  );
Searching $result = $es->search( #  all indices #  all types );
Searching $result = $es->search( index  => 'twitter', type  => 'tweet',  query  => { text => { _all => 'foo' }}, );
Searching $result = $es->search( index  => 'twitter', type  => 'tweet', query b   =>  'foo' , #  b == ElasticSearch::SearchBuilder );
Searching $result = $es->search( index  => 'twitter', type  => 'tweet', query  => { text => { _all => 'foo' }}, sort  => [{ '_score': 'desc' }] );
Searching $result = $es->search( index  => 'twitter', type  => 'tweet', query  => { text => { _all => 'foo' }}, sort  => [{ '_score': 'desc' }] from  => 0, size  => 10, );
Query DSL
Queries   vs  Filters
Queries   vs  Filters  full text & terms terms only
Queries   vs  Filters  full text & terms
relevance scoring terms only
no scoring
Queries   vs  Filters  full text & terms
relevance scoring
slower terms only
no scoring
faster
Queries   vs  Filters  full text & terms
relevance scoring
slower
no caching terms only
no scoring
faster
cacheable
Queries   vs  Filters  full text & terms
relevance scoring
slower
no caching terms only
no scoring
faster
cacheable  Use filters for anything that doesn't affect the relevance score!
Query only Query DSL: $es->search(  query => {  text => { title => 'perl' }  } ); SearchBuilder: $es->search(  query b  => {  title => 'perl'  } );
Filter only Query DSL: $es->search( query => { constant_score => { filter => { term => { tag => 'perl } } } }); SearchBuilder: $es->search( query b  => { -filter => {  tag => 'perl'  } });
Query and filter Query DSL: $es->search( query => { filtered  => { query => {  text => { title => 'perl' } }, filter =>{  term => { tag => 'perl'  } } } }); SearchBuilder: $es->search( query b  => { title  => 'perl', -filter => {  tag => 'perl'  }  });

More Related Content

PDF
ESQUELETO OSSOS CORPO HUMANO.pdf
PPTX
Φύλλα εργασίας και εποπτικό υλικό για τη γλώσσα του α΄ τεύχους της β΄ δημοτικού
PDF
ασκήσεις παρουσίασης
PPTX
Πώς λέμε ΟΧΙ; Φύλλα εργασίας για την 7η -επετειακή- ενότητα της γλώσσας της ...
PPT
Καρτέλες δίψηφων για την Α΄ δημοτικού ασπρόμαυρο (http://blogs.sch.gr/goma/) ...
PDF
τι κρύβει το μπαούλο
PDF
ασκήσεις πάσχα
PDF
Παίζω μαθαίνοντας πρόσθεση μέχρι το είκοσι. Η υπέρβαση της δεκάδας / τα διπλά...
ESQUELETO OSSOS CORPO HUMANO.pdf
Φύλλα εργασίας και εποπτικό υλικό για τη γλώσσα του α΄ τεύχους της β΄ δημοτικού
ασκήσεις παρουσίασης
Πώς λέμε ΟΧΙ; Φύλλα εργασίας για την 7η -επετειακή- ενότητα της γλώσσας της ...
Καρτέλες δίψηφων για την Α΄ δημοτικού ασπρόμαυρο (http://blogs.sch.gr/goma/) ...
τι κρύβει το μπαούλο
ασκήσεις πάσχα
Παίζω μαθαίνοντας πρόσθεση μέχρι το είκοσι. Η υπέρβαση της δεκάδας / τα διπλά...

Similar to Terms of endearment - the ElasticSearch Query DSL explained (20)

ODP
Cool bonsai cool - an introduction to ElasticSearch
PPTX
Elasticsearch Field Data Types
PPTX
Solr vs. Elasticsearch - Case by Case
PDF
06. ElasticSearch : Mapping and Analysis
PDF
Montreal Elasticsearch Meetup
PDF
Solr vs. Elasticsearch, Case by Case: Presented by Alexandre Rafalovitch, UN
KEY
Elasticsearch & "PeopleSearch"
PDF
Data Exploration with Elasticsearch
PDF
Data modeling for Elasticsearch
PDF
Faster and better search results with Elasticsearch
PDF
Simple search with elastic search
PPTX
Introducing ElasticSearch - Ashish
PDF
Использование Elasticsearch для организации поиска по сайту
PPTX
Big data elasticsearch practical
PPTX
Search engine. Elasticsearch
PDF
Introduction to Elasticsearch
PDF
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
PDF
Elasticsearch Basics
PDF
Introduction to Elasticsearch
PDF
Finding the right stuff, an intro to Elasticsearch (at Rug::B)
Cool bonsai cool - an introduction to ElasticSearch
Elasticsearch Field Data Types
Solr vs. Elasticsearch - Case by Case
06. ElasticSearch : Mapping and Analysis
Montreal Elasticsearch Meetup
Solr vs. Elasticsearch, Case by Case: Presented by Alexandre Rafalovitch, UN
Elasticsearch & "PeopleSearch"
Data Exploration with Elasticsearch
Data modeling for Elasticsearch
Faster and better search results with Elasticsearch
Simple search with elastic search
Introducing ElasticSearch - Ashish
Использование Elasticsearch для организации поиска по сайту
Big data elasticsearch practical
Search engine. Elasticsearch
Introduction to Elasticsearch
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
Elasticsearch Basics
Introduction to Elasticsearch
Finding the right stuff, an intro to Elasticsearch (at Rug::B)
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
The AUB Centre for AI in Media Proposal.docx
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
A comparative analysis of optical character recognition models for extracting...
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Empathic Computing: Creating Shared Understanding
Ad

Terms of endearment - the ElasticSearch Query DSL explained