SlideShare a Scribd company logo
Elasticsearch
(Presentation 02)
By
Maruf Hassan
Email: maruf571@gmail.com
Date: 06 April, 2015
ContentContent
● Query DSL
● Queries Vs Filters
● Filters
– term Filter
– terms Filter
– range Filter
– exists and missing Filters
– bool Filter
● Query
– match_all Query
– match Query
– multi_match Query
– Bool Query
● Queries with Filters
Query DSL
There are two types of (query) DSL. filter DSL & query DSL
filter DSL: A filter asks yes/no question of every document and is used for fields that contain exact
values.
Example:
● Is the `created` date in the range `2013` - `2014`?
● Does the `status` field contain the term `published`?
● Is the `lat_lon` field within `10km` of a specified point?
query DSL :A query is similar to a filter, but also asks the question: How well does this document
match? A query calculates how relevant each document is to the query, and assigns it a relevance
`_score`.
Example:
● Best matching the words `full text search`
● Containing the word `run`, but maybe also matching `runs`, `running`, `jog`, or `sprint`
● Containing the words `quick`, `brown`, and `fox`; the closer together they are, the more relevant the
document
Queries Vs Filters
Filter:The output from most filter clauses
--a simple list of the documents that match the filter
--is quick to calculate and easy to cache in memory
Queries: Queries have to not only find matching documents --but also
--calculate how relevant each document is
--query results are not cache.
When to Use Which
● Use query clauses for full-text search or for any condition that should affect the
relevance score
● And use filter clauses for everything else
● Filter is faster :)
Filters
Most important filters
● term Filter
● terms Filter
● range Filter
● exists and missing Filters
● bool Filter
term Filter
The `term` filter is used to filter by exact values,
be they numbers, dates, Booleans, or
not_analyzed` exact-value string fields
Example:
● { "term": { "age": 26 }}
● { "term": { "date": "2014-09-01" }}
● { "term": { "public": true }}
● { "term": { "tag": "full_text" }}
terms Filter
Allows you to specify multiple values to match.
If the field contains any of the specified values,
the document matches
Example:
{ "terms":
{ "tag": [ "search", "full_text", "nosql" ] }
}
range Filter
The `range` filter allows you to find numbers or dates that fall
into a specified range
Example:
{
"range": {
"age": {
"gte": 20,
"lt": 30
}}}
exists and missing Filters
The `exists` and `missing` filters are used to find documents
in which the specified field either has one or more values or
doesn't have any values
Example:
{
"exists": {
"field": "title"
}
}
bool Filter
The `bool` filter is used to combine multiple filter clauses using Boolean logic. It accepts three
parameters
●
must: These clauses must match, like and
●
must_not: These clauses must not match, like not.
●
should: At least one of these clauses must match, like or.
Example:
{ "bool": {
"must": { "term": { "folder": "inbox" }},
"must_not": { "term": { "tag": "spam" }},
"should": [
{ "term": { "starred": true }},
{ "term": { "unread": true }}
]
}}
Query
most important queries
● match_all Query
● match Query
● multi_match Query
● bool Query
match_all Query
The `match_all` query simply matches all
documents. It is the default query that is used if
no query has been specified
Example:
{ "match_all": {}}
match Query
The `match` query should be the standard query that you reach for whenever you want to
query for a full-text or exact value in almost any field.
Example:
● (need analyze the query)
{ "match": { "tweet": "About Search" }}
● (not_analyzed)
{ "match": { "age": 26 }}
{ "match": { "date": "2014-09-01" }}
{ "match": { "public": true }}
{ "match": { "tag": "full_text" }}
multi_match Query
The `multi_match` query allows to run the same `match` query on
multiple fields
Example:
{
"multi_match": {
"query": "full text search",
"fields": [ "title", "body" ]
}
}
bool Query
The `bool` query used to combine multiple query clauses.This query accepts the following parameters:
●
`must`: Clauses that must_match for the document to be included.
●
`must_not`:Clauses that must not match for the document to be included.
● `should`:If these clauses match, they increase the `_score`;
otherwise, they have no effect.
{
"bool": {
"must": { "match": { "title": "how to make millions" }},
"must_not": { "match": { "tag": "spam" }},
"should": [
{ "match": { "tag": "starred" }},
{ "range": { "date": { "gte": "2014-01-01" }}}
]
}
}
Queries with Filters
●
It is often useful to apply a filter to a query or, less frequently, to use a full-text query as a filter.
Filtering a Query
Match Query:
{ "query": { "match": { "interests": internet" }} }
Term filter:
{ "filter": { "range": { "age": { "gte": 18 }}}
Filtering query
GET /cefalo/employee/_search
{ "query": {
"filtered": {
"query": { "match": { "interests": "internet" } },
"filter": { "range": { "age": { "gte": 25 }}
}}}}
Queries with Filters
Just as a Filter
Query: { "query": { "match_all": {}}
Filter: "filter": { "term": { "age": "28" } }
Just filter in a all document
GET /cefalo/employee/_search
{
"query": {
"filtered": {
"query": { "match_all": {}},
"filter": { "term": { "age": "28" } }
}}}
Thanks

More Related Content

Viewers also liked

Passive voice
Passive voicePassive voice
Passive voice
Ika Khasanah
 
Active and Passive Voice
Active and Passive VoiceActive and Passive Voice
Active and Passive VoiceLina Ell
 
Active voice and passive voice
Active voice and passive voiceActive voice and passive voice
Active voice and passive voice
EDIN BROW, DCE, AMET
 
English 6 dlp 42 using the active and passive voice of verbs
English 6 dlp 42   using the active and passive voice of verbsEnglish 6 dlp 42   using the active and passive voice of verbs
English 6 dlp 42 using the active and passive voice of verbsEDITHA HONRADEZ
 
Newspaper Reports: Passive Voice
Newspaper Reports: Passive VoiceNewspaper Reports: Passive Voice
Newspaper Reports: Passive Voice
Inma Alvarez
 

Viewers also liked (6)

The passive voice manual
The passive voice manualThe passive voice manual
The passive voice manual
 
Passive voice
Passive voicePassive voice
Passive voice
 
Active and Passive Voice
Active and Passive VoiceActive and Passive Voice
Active and Passive Voice
 
Active voice and passive voice
Active voice and passive voiceActive voice and passive voice
Active voice and passive voice
 
English 6 dlp 42 using the active and passive voice of verbs
English 6 dlp 42   using the active and passive voice of verbsEnglish 6 dlp 42   using the active and passive voice of verbs
English 6 dlp 42 using the active and passive voice of verbs
 
Newspaper Reports: Passive Voice
Newspaper Reports: Passive VoiceNewspaper Reports: Passive Voice
Newspaper Reports: Passive Voice
 

Similar to Elastic search presentation 2

08. ElasticSearch : Sorting and Relevance
08.  ElasticSearch : Sorting and Relevance08.  ElasticSearch : Sorting and Relevance
08. ElasticSearch : Sorting and Relevance
OpenThink Labs
 
06. ElasticSearch : Mapping and Analysis
06. ElasticSearch : Mapping and Analysis06. ElasticSearch : Mapping and Analysis
06. ElasticSearch : Mapping and Analysis
OpenThink Labs
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In Elasticsearch
Knoldus Inc.
 
Elasticsearch for Data Engineers
Elasticsearch for Data EngineersElasticsearch for Data Engineers
Elasticsearch for Data Engineers
Duy Do
 
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Kai Chan
 
Harnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, Germany
Harnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, GermanyHarnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, Germany
Harnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, Germany
André Ricardo Barreto de Oliveira
 
Google power search
Google power searchGoogle power search
Google power search
Muhammed Shokr
 
Cheatsheet: Google Search
Cheatsheet: Google SearchCheatsheet: Google Search
Cheatsheet: Google Search
Kasper de Waard
 
Google Search Cheat Sheet
Google Search Cheat SheetGoogle Search Cheat Sheet
Google Search Cheat Sheet
Tiffany Hamburg Hamburg
 
Amrapali builders -- google cheatsheet.pdf
Amrapali builders -- google cheatsheet.pdfAmrapali builders -- google cheatsheet.pdf
Amrapali builders -- google cheatsheet.pdf
amrapalibuildersreviews
 
Kibana: Real-World Examples
Kibana: Real-World ExamplesKibana: Real-World Examples
Kibana: Real-World Examples
Salvatore Cordiano
 
Search Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and SolrSearch Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and Solr
Kai Chan
 
Power of SPL Breakout Session
Power of SPL Breakout SessionPower of SPL Breakout Session
Power of SPL Breakout Session
Splunk
 
Enhancement of Searching and Analyzing the Document using Elastic Search
Enhancement of Searching and Analyzing the Document using Elastic SearchEnhancement of Searching and Analyzing the Document using Elastic Search
Enhancement of Searching and Analyzing the Document using Elastic Search
IRJET Journal
 
Power of SPL
Power of SPLPower of SPL
Power of SPL
Splunk
 
databases2
databases2databases2
databases2c.west
 
Google cheatsheet
Google cheatsheetGoogle cheatsheet
Google cheatsheet
Alejandro Rivera Santander
 
Data modeling for Elasticsearch
Data modeling for ElasticsearchData modeling for Elasticsearch
Data modeling for Elasticsearch
Florian Hopf
 
Power of SPL Breakout Session
Power of SPL Breakout SessionPower of SPL Breakout Session
Power of SPL Breakout Session
Splunk
 
Search explained T3DD15
Search explained T3DD15Search explained T3DD15
Search explained T3DD15
Hans Höchtl
 

Similar to Elastic search presentation 2 (20)

08. ElasticSearch : Sorting and Relevance
08.  ElasticSearch : Sorting and Relevance08.  ElasticSearch : Sorting and Relevance
08. ElasticSearch : Sorting and Relevance
 
06. ElasticSearch : Mapping and Analysis
06. ElasticSearch : Mapping and Analysis06. ElasticSearch : Mapping and Analysis
06. ElasticSearch : Mapping and Analysis
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In Elasticsearch
 
Elasticsearch for Data Engineers
Elasticsearch for Data EngineersElasticsearch for Data Engineers
Elasticsearch for Data Engineers
 
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
 
Harnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, Germany
Harnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, GermanyHarnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, Germany
Harnessing The Power of Search - Liferay DEVCON 2015, Darmstadt, Germany
 
Google power search
Google power searchGoogle power search
Google power search
 
Cheatsheet: Google Search
Cheatsheet: Google SearchCheatsheet: Google Search
Cheatsheet: Google Search
 
Google Search Cheat Sheet
Google Search Cheat SheetGoogle Search Cheat Sheet
Google Search Cheat Sheet
 
Amrapali builders -- google cheatsheet.pdf
Amrapali builders -- google cheatsheet.pdfAmrapali builders -- google cheatsheet.pdf
Amrapali builders -- google cheatsheet.pdf
 
Kibana: Real-World Examples
Kibana: Real-World ExamplesKibana: Real-World Examples
Kibana: Real-World Examples
 
Search Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and SolrSearch Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and Solr
 
Power of SPL Breakout Session
Power of SPL Breakout SessionPower of SPL Breakout Session
Power of SPL Breakout Session
 
Enhancement of Searching and Analyzing the Document using Elastic Search
Enhancement of Searching and Analyzing the Document using Elastic SearchEnhancement of Searching and Analyzing the Document using Elastic Search
Enhancement of Searching and Analyzing the Document using Elastic Search
 
Power of SPL
Power of SPLPower of SPL
Power of SPL
 
databases2
databases2databases2
databases2
 
Google cheatsheet
Google cheatsheetGoogle cheatsheet
Google cheatsheet
 
Data modeling for Elasticsearch
Data modeling for ElasticsearchData modeling for Elasticsearch
Data modeling for Elasticsearch
 
Power of SPL Breakout Session
Power of SPL Breakout SessionPower of SPL Breakout Session
Power of SPL Breakout Session
 
Search explained T3DD15
Search explained T3DD15Search explained T3DD15
Search explained T3DD15
 

Recently uploaded

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 

Recently uploaded (20)

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 

Elastic search presentation 2

  • 1. Elasticsearch (Presentation 02) By Maruf Hassan Email: maruf571@gmail.com Date: 06 April, 2015
  • 2. ContentContent ● Query DSL ● Queries Vs Filters ● Filters – term Filter – terms Filter – range Filter – exists and missing Filters – bool Filter ● Query – match_all Query – match Query – multi_match Query – Bool Query ● Queries with Filters
  • 3. Query DSL There are two types of (query) DSL. filter DSL & query DSL filter DSL: A filter asks yes/no question of every document and is used for fields that contain exact values. Example: ● Is the `created` date in the range `2013` - `2014`? ● Does the `status` field contain the term `published`? ● Is the `lat_lon` field within `10km` of a specified point? query DSL :A query is similar to a filter, but also asks the question: How well does this document match? A query calculates how relevant each document is to the query, and assigns it a relevance `_score`. Example: ● Best matching the words `full text search` ● Containing the word `run`, but maybe also matching `runs`, `running`, `jog`, or `sprint` ● Containing the words `quick`, `brown`, and `fox`; the closer together they are, the more relevant the document
  • 4. Queries Vs Filters Filter:The output from most filter clauses --a simple list of the documents that match the filter --is quick to calculate and easy to cache in memory Queries: Queries have to not only find matching documents --but also --calculate how relevant each document is --query results are not cache. When to Use Which ● Use query clauses for full-text search or for any condition that should affect the relevance score ● And use filter clauses for everything else ● Filter is faster :)
  • 5. Filters Most important filters ● term Filter ● terms Filter ● range Filter ● exists and missing Filters ● bool Filter
  • 6. term Filter The `term` filter is used to filter by exact values, be they numbers, dates, Booleans, or not_analyzed` exact-value string fields Example: ● { "term": { "age": 26 }} ● { "term": { "date": "2014-09-01" }} ● { "term": { "public": true }} ● { "term": { "tag": "full_text" }}
  • 7. terms Filter Allows you to specify multiple values to match. If the field contains any of the specified values, the document matches Example: { "terms": { "tag": [ "search", "full_text", "nosql" ] } }
  • 8. range Filter The `range` filter allows you to find numbers or dates that fall into a specified range Example: { "range": { "age": { "gte": 20, "lt": 30 }}}
  • 9. exists and missing Filters The `exists` and `missing` filters are used to find documents in which the specified field either has one or more values or doesn't have any values Example: { "exists": { "field": "title" } }
  • 10. bool Filter The `bool` filter is used to combine multiple filter clauses using Boolean logic. It accepts three parameters ● must: These clauses must match, like and ● must_not: These clauses must not match, like not. ● should: At least one of these clauses must match, like or. Example: { "bool": { "must": { "term": { "folder": "inbox" }}, "must_not": { "term": { "tag": "spam" }}, "should": [ { "term": { "starred": true }}, { "term": { "unread": true }} ] }}
  • 11. Query most important queries ● match_all Query ● match Query ● multi_match Query ● bool Query
  • 12. match_all Query The `match_all` query simply matches all documents. It is the default query that is used if no query has been specified Example: { "match_all": {}}
  • 13. match Query The `match` query should be the standard query that you reach for whenever you want to query for a full-text or exact value in almost any field. Example: ● (need analyze the query) { "match": { "tweet": "About Search" }} ● (not_analyzed) { "match": { "age": 26 }} { "match": { "date": "2014-09-01" }} { "match": { "public": true }} { "match": { "tag": "full_text" }}
  • 14. multi_match Query The `multi_match` query allows to run the same `match` query on multiple fields Example: { "multi_match": { "query": "full text search", "fields": [ "title", "body" ] } }
  • 15. bool Query The `bool` query used to combine multiple query clauses.This query accepts the following parameters: ● `must`: Clauses that must_match for the document to be included. ● `must_not`:Clauses that must not match for the document to be included. ● `should`:If these clauses match, they increase the `_score`; otherwise, they have no effect. { "bool": { "must": { "match": { "title": "how to make millions" }}, "must_not": { "match": { "tag": "spam" }}, "should": [ { "match": { "tag": "starred" }}, { "range": { "date": { "gte": "2014-01-01" }}} ] } }
  • 16. Queries with Filters ● It is often useful to apply a filter to a query or, less frequently, to use a full-text query as a filter. Filtering a Query Match Query: { "query": { "match": { "interests": internet" }} } Term filter: { "filter": { "range": { "age": { "gte": 18 }}} Filtering query GET /cefalo/employee/_search { "query": { "filtered": { "query": { "match": { "interests": "internet" } }, "filter": { "range": { "age": { "gte": 25 }} }}}}
  • 17. Queries with Filters Just as a Filter Query: { "query": { "match_all": {}} Filter: "filter": { "term": { "age": "28" } } Just filter in a all document GET /cefalo/employee/_search { "query": { "filtered": { "query": { "match_all": {}}, "filter": { "term": { "age": "28" } } }}}