SlideShare ist ein Scribd-Unternehmen logo
1 von 18
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

Weitere ähnliche Inhalte

Andere mochten auch

Active and Passive Voice
Active and Passive VoiceActive and Passive Voice
Active and Passive VoiceLina Ell
 
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 VoiceInma Alvarez
 

Andere mochten auch (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
 

Ähnlich wie Elastic search presentation 2

08. ElasticSearch : Sorting and Relevance
08.  ElasticSearch : Sorting and Relevance08.  ElasticSearch : Sorting and Relevance
08. ElasticSearch : Sorting and RelevanceOpenThink Labs
 
06. ElasticSearch : Mapping and Analysis
06. ElasticSearch : Mapping and Analysis06. ElasticSearch : Mapping and Analysis
06. ElasticSearch : Mapping and AnalysisOpenThink Labs
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In ElasticsearchKnoldus Inc.
 
Elasticsearch for Data Engineers
Elasticsearch for Data EngineersElasticsearch for Data Engineers
Elasticsearch for Data EngineersDuy 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, GermanyAndré Ricardo Barreto de Oliveira
 
Cheatsheet: Google Search
Cheatsheet: Google SearchCheatsheet: Google Search
Cheatsheet: Google SearchKasper de Waard
 
Amrapali builders -- google cheatsheet.pdf
Amrapali builders -- google cheatsheet.pdfAmrapali builders -- google cheatsheet.pdf
Amrapali builders -- google cheatsheet.pdfamrapalibuildersreviews
 
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 SolrKai Chan
 
Power of SPL Breakout Session
Power of SPL Breakout SessionPower of SPL Breakout Session
Power of SPL Breakout SessionSplunk
 
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 SearchIRJET Journal
 
Power of SPL
Power of SPLPower of SPL
Power of SPLSplunk
 
databases2
databases2databases2
databases2c.west
 
Data modeling for Elasticsearch
Data modeling for ElasticsearchData modeling for Elasticsearch
Data modeling for ElasticsearchFlorian Hopf
 
Power of SPL Breakout Session
Power of SPL Breakout SessionPower of SPL Breakout Session
Power of SPL Breakout SessionSplunk
 
Search explained T3DD15
Search explained T3DD15Search explained T3DD15
Search explained T3DD15Hans Höchtl
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Kürzlich hochgeladen (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

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" } } }}}