Elastic Search
Pavan Navule
Contents
▪ Introduction
▪ Terminology
– Index,Type, Document, Field
– Comparison with Relational Database
▪ Architecture
– Clusters, Nodes, Shards & Replicas
▪ Search
– How it works?
– Inverted Index
▪ Installation & Configuration
– Setup & Run Elastic Server
▪ Elastic in Action
– Indexing, Querying & Deleting
Introduction
Distributed
Terminology
▪ Index
– Is means of storing different types of data.
– Can span across one primary shard or multiple shards.
– Identified by metadata field _index
– An Index can contain multiple types
Terminology
▪ Type
– A type is a convenient way to store a specific type of data within an
index
– Identified by metadata field _type
Terminology
▪ Document
– A document is JSON object (set of
‘key-value’ pairs aka fields)
▪ _type
▪ _id
▪ _source
Terminology
▪ Field
– Key
▪ type (data type)
▪ Format
– Value
▪ Can hold scalar data (int, string values)
or Nested structures like array or
object
Terminology (Comparison with RDBMS)
Id Status
1 Reserved
2 In House
3 Departed
1 Reserved
Architecture
https://prezi.com/hmxfrorhtcq-/elasticsearch/
Search
How Elastic Search Works?
N
N
N
N
Cluster
• Master Node
• Multicast to find other nodes
• Manage Cluster State
• Assign Shards to Nodes
N
N
N
N
Search
How Elastic Search Works?
N
N
N
Cluster Replica
Search
Internode Communication
• Sends parallel Queries to all nodes
• Merges the full response
• Response returned to the user
N
N
N
Cluster
P2P Architecture
Default Port 9300
Search
Inverted Index
Text Processing
• Tokenize
• Remove
duplicates
• Sort
Math
• Frequency
Discover
• Identify &
List the
documents
Search
Doc # Contents
1 Fantastic Beasts and Where to FindThem
2 Beasts of the SouthernWild
3 The Wild Life
4 Life of a Pi
Term Frequency Documents
and 2 1
beasts 2 1,2
fantastic 1 1
find 1 1
life 2 3,4
of 2 2,4
pi 1 4
southern 1 2
the 2 2,3
them 1 1
to 1 1
where 1 1
wild 2 2,3
Inverted Index
Installation
▪ Download from
www.elastic.co/downloads/elasticsearch
– Extract to your desired location
▪ Configuration
– Default port 9200
– Configure
▪ Config file location “~/elasticsearch-x.y.z/config/elasticsearch.yml“
▪ node name
▪ port
▪ path for log files etc.,
Run Elastic Server
▪ Go to “~/elasticsearch-2.4.0/bin/“
▪ Double click “elasticsearch.bat”
Indexing
Syntax
POST /{index}/{type}/{optional-id}
{
“key-1": "value",
"key-2": "value",
...
"key-n": "value",
}
Example
POST /sampleindex/sampletype/
{
"guestname": "Mr.J",
"arrivaldate": "2016/12/12",
"departuredate": "2016/12/14"
}
Querying
Syntax Example
Search
GET /{index}/_search GET demo/_search
Search by type & id
GET /{index}/{type}/{id} GET demo/reservation/1
Search by property
GET /{index}/_search?q={propName}=“value" GET /demo/_search?q=guestname="Mr.J"
Free search across index
GET /{index}/_search?q=‘value' GET demo/reservation/1
Deleting a Document
DELETE /{Index}/{Type}/{Id}
Eg:
DELETE demo/reservation/1
Review
▪ Introduction
▪ Terminology
– Index,Type, Document, Field
– Comparison with Relational Database
▪ Architecture
– Clusters, Nodes, Shards & Replicas
▪ Search
– How it works?
– Inverted Index
▪ Installation & Configuration
– Setup & Run Elastic Server
▪ Elastic in Action
– Indexing, Querying & Deleting
Elastic Search
Elastic Search

Elastic Search