You are on page 1of 22

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
Architecture

https://prezi.com/hmxfrorhtcq-/elasticsearch/
Search

How Elastic Search Works?

Cluster
N
• Master Node
• Multicast to find other nodes
• Manage Cluster State N N
• Assign Shards to Nodes

N
Search

How Elastic Search Works?

Cluster Replica
N

N N

N
Search

Internode Communication
Cluster
N
• Sends parallel Queries to all nodes

• Merges the full response N

• Response returned to the user P2P Architecture


N
Default Port 9300
Search

Inverted Index

Text Processing Math Discover

• Tokenize
• Remove • Frequency • Identify &
duplicates List the
• Sort documents
Search

Inverted Index Term Frequency Documents


and 2 1
beasts 2 1,2
Doc # Contents fantastic 1 1
1 Fantastic Beasts and Where to Find Them find 1 1
2 Beasts of the Southern Wild life 2 3,4
3 The Wild Life of 2 2,4
4 Life of a Pi pi 1 4
southern 1 2
the 2 2,3
them 1 1
to 1 1
where 1 1
wild 2 2,3
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 Example
POST /{index}/{type}/{optional-id} POST /sampleindex/sampletype/
{ {

“key-1": "value", "guestname": "Mr.J",

"key-2": "value", "arrivaldate": "2016/12/12",

... "departuredate": "2016/12/14"

"key-n": "value", }

}
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

You might also like