SlideShare a Scribd company logo
1 of 27
Deep Dive Into Elasticsearch
Kunal Kapoor
Software Consultant
Knoldus Software LLP
AGENDA
● What is Elasticsearch
● Getting Started
● Key Terminologies
● CRUD Operations
● Understanding the physical layout
● What happens when you index a document
● How to make an inverted index mutable
● How per-segment search works
● How a delete operation works
● Segment Merging
What is Elasticsearch
● Search engine based on Lucene.
● Provides near real-time search
● Distributed
● Fault Tolerant
● Notable users:
– Facebook
– Github
– CERN
– LinkedIn
Getting Started
● Download the elasticsearch distribution from
https://www.elastic.co/downloads/elasticsearch
● To start the elasticsearch server run the following
command from within the extracted directory
– ./bin/elasticsearch
● Once the server or node is created you can check the
health of your cluster by running
– curl 'localhost:9200/_cat/health?v'
Key Terminologies
● Node - A node is a single server that is part of your
cluster, stores your data, and participates in the cluster’s
indexing and search capabilities
● Cluster - A cluster is a collection of one or more nodes
(servers) that together holds your entire data and
provides indexing and search capabilities across all
nodes.
● Index - An index is a collection of documents that have
somewhat similar characteristics.
Key Terminologies
● Type - A type is a logical category/partition of your index.
It is defined for documents that have a set of common
fields.
● Shard – A shard is basically an lucene index. Contains
the documents and various data structures that help in
searching.
CRUD Operations
● Indexing a document
– curl -XPOST 'localhost:9200/test/test/1?pretty' -d '{"text":"Hello World"}'
● Updating a document
– curl -XPOST 'localhost:9200/test/test/1?pretty' -d '{"text":"Hello"}'
● Delete a document
– curl -XDELETE 'localhost:9200/test/test/1?pretty'
● Search a document
– curl -XPOST 'localhost:9200/test/_search?pretty' -d '{"query":
{ "match": {"text": "hello" }}}'
Understanding the physical layout
SHARDS
(Lucene indices)
SEGMENTS
Inverted Index
● Data structure storing a mapping, from content such as
words or numbers, to its locations in a database file, or a
set of documents.
● Provides full-text search
● Consists of 2 parts
– Sorted Dictionary
– Postings
● Immutable
What happens when you index a
document?
● The node that receives the request becomes the
controller for that request.
● That node determines the shard in which the document
should reside on the basis of the documents Id.
– shard = hash(document_id) % number_of_primary_shards
● The request is then forwarded to the appropriate node
which contains the shard.
● The node forwards the request to the appropriate shard.
What happens when you index a
document?
● The shard performs analysis on the document and creates the
appropriate inverted index which is helpful for searching.
● The request is then sent to the replica shards.
● The documents are analyzed by the standard analyzer by
default.
● It split the documents on white-space and lowercases the
documents.
● The documents are then ready to be inserted in the inverted
index
What happens when you index a
document?
{
“text”:”Elasticsearch is an awesome search engine”
}
{
“text:”Elasticsearch is not a database”
}
elasticsearch, is, an, awesome, search, engine, elasticsearch,not, a, database
Terms Document1 Document2
elasticsearch ✓ ✓
is ✓ ✓
an ✓ -
awesome ✓ -
search ✓ -
engine ✓ -
not - ✓
a - ✓
database - ✓
How to make an inverted index
mutable?
● Earlier, the whole inverted index would be rewritten to
disk with the changes.
● Very costly approach
● Lucene introduced the concept of per-segment search.
● Now a Lucene index would mean a collection of
segments plus a commit point.
● A commit point is a file that contains the list of segments
that are ready for search.
How per-segment search works?
● New documents are collected in an in-memory buffer.
● Every so often, the buffer is commited (refresh)
– A new supplementary segment with a commit point is
written to file-system cache.
– The transaction log is updated with the request for a
full commit later.
● The buffer is cleared and the segment is made available
for search.
In-memory Buffer
COMMIT POINT
Transaction Log
How a delete operation works?
● Every shard in the Elasticsearch node maintains a .del file
along with the commit point.
● .del file lists which documents in which segments have
been deleted.
● When a delete request is encountered, the appropriate
document is marked as deleted.
● The deleted document will still match the search query but
will be filtered later on.
● Later the document is purged from the file-system while
segment merging.
Segment Merging
● Each segment consumes file handles, memory, and CPU
cycles.
● The more the number of segments, the slower the search
will be.
● Elasticsearch solves this problem by merging segments
in the background.
● Small segments are merged into bigger segments.
● This is the moment when those old deleted documents
are purged from the file-system.
Segment Merging
● This is how the merge process works:-
– The merge process selects a few segments of similar
size and merges them into a new bigger segment in
the background.
– The new segment is flushed to disk.
– A new commit point is written that includes the new
segment and excludes the old, smaller segments.
– The new segment is opened for search.
– The old segments are deleted.
References
● The Definitive Guide by Clinton Gormley and Zachary
Tong
● https://www.elastic.co/guide/en/elasticsearch/reference/current/
Questions?
References
● The Definitive Guide by Clinton Gormley and Zachary
Tong
● https://www.elastic.co/guide/en/elasticsearch/reference/current/
THANK YOU

More Related Content

What's hot

Introduction à ElasticSearch
Introduction à ElasticSearchIntroduction à ElasticSearch
Introduction à ElasticSearch
Fadel Chafai
 

What's hot (20)

Elasticsearch for beginners
Elasticsearch for beginnersElasticsearch for beginners
Elasticsearch for beginners
 
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
 
Elasticsearch From the Bottom Up
Elasticsearch From the Bottom UpElasticsearch From the Bottom Up
Elasticsearch From the Bottom Up
 
Elasticsearch
ElasticsearchElasticsearch
Elasticsearch
 
Elasticsearch Introduction
Elasticsearch IntroductionElasticsearch Introduction
Elasticsearch Introduction
 
Intro to elasticsearch
Intro to elasticsearchIntro to elasticsearch
Intro to elasticsearch
 
An Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and KibanaAn Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and Kibana
 
What I learnt: Elastic search & Kibana : introduction, installtion & configur...
What I learnt: Elastic search & Kibana : introduction, installtion & configur...What I learnt: Elastic search & Kibana : introduction, installtion & configur...
What I learnt: Elastic search & Kibana : introduction, installtion & configur...
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
ElasticSearch
ElasticSearchElasticSearch
ElasticSearch
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1
 
Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack Introduction
 
Elasticsearch
ElasticsearchElasticsearch
Elasticsearch
 
Introduction à ElasticSearch
Introduction à ElasticSearchIntroduction à ElasticSearch
Introduction à ElasticSearch
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search
 
Elasticsearch for Data Analytics
Elasticsearch for Data AnalyticsElasticsearch for Data Analytics
Elasticsearch for Data Analytics
 
검색엔진이 데이터를 다루는 법 김종민
검색엔진이 데이터를 다루는 법 김종민검색엔진이 데이터를 다루는 법 김종민
검색엔진이 데이터를 다루는 법 김종민
 
Intro to Elasticsearch
Intro to ElasticsearchIntro to Elasticsearch
Intro to Elasticsearch
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack Presentation
 
ELK Stack
ELK StackELK Stack
ELK Stack
 

Viewers also liked

Tachyon meetup San Francisco Oct 2014
Tachyon meetup San Francisco Oct 2014Tachyon meetup San Francisco Oct 2014
Tachyon meetup San Francisco Oct 2014
Claudiu Barbura
 

Viewers also liked (20)

Elasticsearch cluster deep dive
Elasticsearch  cluster deep diveElasticsearch  cluster deep dive
Elasticsearch cluster deep dive
 
Elasticsearch for Logs & Metrics - a deep dive
Elasticsearch for Logs & Metrics - a deep diveElasticsearch for Logs & Metrics - a deep dive
Elasticsearch for Logs & Metrics - a deep dive
 
AWS re:Invent 2016: How to Scale and Operate Elasticsearch on AWS (DEV307)
AWS re:Invent 2016: How to Scale and Operate Elasticsearch on AWS (DEV307)AWS re:Invent 2016: How to Scale and Operate Elasticsearch on AWS (DEV307)
AWS re:Invent 2016: How to Scale and Operate Elasticsearch on AWS (DEV307)
 
Alluxio
AlluxioAlluxio
Alluxio
 
Tachyon meetup San Francisco Oct 2014
Tachyon meetup San Francisco Oct 2014Tachyon meetup San Francisco Oct 2014
Tachyon meetup San Francisco Oct 2014
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JS
 
Getting Started With AureliaJs
Getting Started With AureliaJsGetting Started With AureliaJs
Getting Started With AureliaJs
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 
Akka streams
Akka streamsAkka streams
Akka streams
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An Introduction
 
Mailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdomMailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdom
 
String interpolation
String interpolationString interpolation
String interpolation
 
Kanban
KanbanKanban
Kanban
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 
An Introduction to Quill
An Introduction to QuillAn Introduction to Quill
An Introduction to Quill
 
Introduction to Scala Macros
Introduction to Scala MacrosIntroduction to Scala Macros
Introduction to Scala Macros
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Mandrill Templates
Mandrill TemplatesMandrill Templates
Mandrill Templates
 
Introduction to Knockout Js
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout Js
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
 

Similar to Deep Dive Into Elasticsearch

Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...
Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...
Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...
Data Con LA
 
Elasticsearch Data Analyses
Elasticsearch Data AnalysesElasticsearch Data Analyses
Elasticsearch Data Analyses
Alaa Elhadba
 

Similar to Deep Dive Into Elasticsearch (20)

Elasticsearch Architechture
Elasticsearch ArchitechtureElasticsearch Architechture
Elasticsearch Architechture
 
Elastic search
Elastic searchElastic search
Elastic search
 
Roaring with elastic search sangam2018
Roaring with elastic search sangam2018Roaring with elastic search sangam2018
Roaring with elastic search sangam2018
 
ELK-Stack-Essential-Concepts-TheELKStack-LunchandLearn.pdf
ELK-Stack-Essential-Concepts-TheELKStack-LunchandLearn.pdfELK-Stack-Essential-Concepts-TheELKStack-LunchandLearn.pdf
ELK-Stack-Essential-Concepts-TheELKStack-LunchandLearn.pdf
 
Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...
Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...
Data Con LA 2022 - Pre- Recorded - OpenSearch: Everything You Need to Know Ab...
 
Elasticsearch selected topics
Elasticsearch selected topicsElasticsearch selected topics
Elasticsearch selected topics
 
[2 d1] elasticsearch 성능 최적화
[2 d1] elasticsearch 성능 최적화[2 d1] elasticsearch 성능 최적화
[2 d1] elasticsearch 성능 최적화
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stack
 
[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화[2D1]Elasticsearch 성능 최적화
[2D1]Elasticsearch 성능 최적화
 
No sq lv1_0
No sq lv1_0No sq lv1_0
No sq lv1_0
 
Centralized Logging System Using ELK Stack
Centralized Logging System Using ELK StackCentralized Logging System Using ELK Stack
Centralized Logging System Using ELK Stack
 
Filebeat Elastic Search Presentation.pptx
Filebeat Elastic Search Presentation.pptxFilebeat Elastic Search Presentation.pptx
Filebeat Elastic Search Presentation.pptx
 
Elasticsearch Introduction at BigData meetup
Elasticsearch Introduction at BigData meetupElasticsearch Introduction at BigData meetup
Elasticsearch Introduction at BigData meetup
 
Managing Security At 1M Events a Second using Elasticsearch
Managing Security At 1M Events a Second using ElasticsearchManaging Security At 1M Events a Second using Elasticsearch
Managing Security At 1M Events a Second using Elasticsearch
 
Elasticsearch tuning
Elasticsearch tuningElasticsearch tuning
Elasticsearch tuning
 
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search EngineElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
ElasticSearch: Distributed Multitenant NoSQL Datastore and Search Engine
 
Elasticsearch - Scalability and Multitenancy
Elasticsearch - Scalability and MultitenancyElasticsearch - Scalability and Multitenancy
Elasticsearch - Scalability and Multitenancy
 
Elasticsearch Data Analyses
Elasticsearch Data AnalysesElasticsearch Data Analyses
Elasticsearch Data Analyses
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
 
Configuring elasticsearch for performance and scale
Configuring elasticsearch for performance and scaleConfiguring elasticsearch for performance and scale
Configuring elasticsearch for performance and scale
 

More from Knoldus Inc.

More from Knoldus Inc. (20)

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRA
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Recently uploaded (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.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 🔝✔️✔️
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 

Deep Dive Into Elasticsearch

  • 1. Deep Dive Into Elasticsearch Kunal Kapoor Software Consultant Knoldus Software LLP
  • 2. AGENDA ● What is Elasticsearch ● Getting Started ● Key Terminologies ● CRUD Operations ● Understanding the physical layout ● What happens when you index a document ● How to make an inverted index mutable ● How per-segment search works ● How a delete operation works ● Segment Merging
  • 3. What is Elasticsearch ● Search engine based on Lucene. ● Provides near real-time search ● Distributed ● Fault Tolerant ● Notable users: – Facebook – Github – CERN – LinkedIn
  • 4. Getting Started ● Download the elasticsearch distribution from https://www.elastic.co/downloads/elasticsearch ● To start the elasticsearch server run the following command from within the extracted directory – ./bin/elasticsearch ● Once the server or node is created you can check the health of your cluster by running – curl 'localhost:9200/_cat/health?v'
  • 5. Key Terminologies ● Node - A node is a single server that is part of your cluster, stores your data, and participates in the cluster’s indexing and search capabilities ● Cluster - A cluster is a collection of one or more nodes (servers) that together holds your entire data and provides indexing and search capabilities across all nodes. ● Index - An index is a collection of documents that have somewhat similar characteristics.
  • 6. Key Terminologies ● Type - A type is a logical category/partition of your index. It is defined for documents that have a set of common fields. ● Shard – A shard is basically an lucene index. Contains the documents and various data structures that help in searching.
  • 7. CRUD Operations ● Indexing a document – curl -XPOST 'localhost:9200/test/test/1?pretty' -d '{"text":"Hello World"}' ● Updating a document – curl -XPOST 'localhost:9200/test/test/1?pretty' -d '{"text":"Hello"}' ● Delete a document – curl -XDELETE 'localhost:9200/test/test/1?pretty' ● Search a document – curl -XPOST 'localhost:9200/test/_search?pretty' -d '{"query": { "match": {"text": "hello" }}}'
  • 11.
  • 12. Inverted Index ● Data structure storing a mapping, from content such as words or numbers, to its locations in a database file, or a set of documents. ● Provides full-text search ● Consists of 2 parts – Sorted Dictionary – Postings ● Immutable
  • 13. What happens when you index a document? ● The node that receives the request becomes the controller for that request. ● That node determines the shard in which the document should reside on the basis of the documents Id. – shard = hash(document_id) % number_of_primary_shards ● The request is then forwarded to the appropriate node which contains the shard. ● The node forwards the request to the appropriate shard.
  • 14. What happens when you index a document? ● The shard performs analysis on the document and creates the appropriate inverted index which is helpful for searching. ● The request is then sent to the replica shards. ● The documents are analyzed by the standard analyzer by default. ● It split the documents on white-space and lowercases the documents. ● The documents are then ready to be inserted in the inverted index
  • 15. What happens when you index a document? { “text”:”Elasticsearch is an awesome search engine” } { “text:”Elasticsearch is not a database” }
  • 16. elasticsearch, is, an, awesome, search, engine, elasticsearch,not, a, database
  • 17. Terms Document1 Document2 elasticsearch ✓ ✓ is ✓ ✓ an ✓ - awesome ✓ - search ✓ - engine ✓ - not - ✓ a - ✓ database - ✓
  • 18. How to make an inverted index mutable? ● Earlier, the whole inverted index would be rewritten to disk with the changes. ● Very costly approach ● Lucene introduced the concept of per-segment search. ● Now a Lucene index would mean a collection of segments plus a commit point. ● A commit point is a file that contains the list of segments that are ready for search.
  • 19. How per-segment search works? ● New documents are collected in an in-memory buffer. ● Every so often, the buffer is commited (refresh) – A new supplementary segment with a commit point is written to file-system cache. – The transaction log is updated with the request for a full commit later. ● The buffer is cleared and the segment is made available for search.
  • 21. How a delete operation works? ● Every shard in the Elasticsearch node maintains a .del file along with the commit point. ● .del file lists which documents in which segments have been deleted. ● When a delete request is encountered, the appropriate document is marked as deleted. ● The deleted document will still match the search query but will be filtered later on. ● Later the document is purged from the file-system while segment merging.
  • 22. Segment Merging ● Each segment consumes file handles, memory, and CPU cycles. ● The more the number of segments, the slower the search will be. ● Elasticsearch solves this problem by merging segments in the background. ● Small segments are merged into bigger segments. ● This is the moment when those old deleted documents are purged from the file-system.
  • 23. Segment Merging ● This is how the merge process works:- – The merge process selects a few segments of similar size and merges them into a new bigger segment in the background. – The new segment is flushed to disk. – A new commit point is written that includes the new segment and excludes the old, smaller segments. – The new segment is opened for search. – The old segments are deleted.
  • 24. References ● The Definitive Guide by Clinton Gormley and Zachary Tong ● https://www.elastic.co/guide/en/elasticsearch/reference/current/
  • 26. References ● The Definitive Guide by Clinton Gormley and Zachary Tong ● https://www.elastic.co/guide/en/elasticsearch/reference/current/

Editor's Notes

  1. 1. It allows you to explore your data at a speed. 2. Distributed-- 2 or more servers can be started at different locations and the data will be stored on both of them. 3. fault- Es-index is distributed across different nodes As the nodes are distributed across different zones, it is unlikely that a failure affects both the servers at the same time
  2. Es is configured to use multicast out of the box.In multicast it sends UDP pings across the local network to discover the nodes. Other nodes receive this ping and respond thus creating a cluster. Not good for production as it can also discover unwanted nodes if cluster name is same Thus unicast is used which accepts IpAddress of nodes that you want to add in the cluster
  3. A node has multiple shards within themAn Es index can span across multiple nodes through shards. A shard is the lowest level worker that contains the data that is inserted in the index.
  4. A lucene index or a shard contains various segments that are like mini indicesThese indices contain the datastructures required by elasticsearch to provide near-real time search.