40

Introduction to Elasticsearch

Embed Size (px)

Citation preview

Page 1: Introduction to Elasticsearch
Page 2: Introduction to Elasticsearch

§ § § § § § 

Agenda

Page 3: Introduction to Elasticsearch

Why Elasticsearch?

Page 4: Introduction to Elasticsearch

Fuzzy Searches

Page 5: Introduction to Elasticsearch

Relevant Searches

Page 6: Introduction to Elasticsearch

Pagination

Page 7: Introduction to Elasticsearch

Aggregations

Page 8: Introduction to Elasticsearch

§ § § § § § 

Derivatives

Page 9: Introduction to Elasticsearch

Suggestions

Page 10: Introduction to Elasticsearch

Elasticsearch vs RelationalDB

Node 1

index = books

index = blogs

RDBMS

database = books

database = blogs

type = travel

type = cooking

type = travel

type = cooking

table= travel

table= cooking

table = travel

table = cooking

Page 11: Introduction to Elasticsearch

Scaling & Sharding

Node 1

primary shard 1

primary shard 2

primary shard 3

primary shard 4

primary shard 5

Page 12: Introduction to Elasticsearch

Scaling & Sharding contd..

Node 1

Node 2

Node 3

primaryshard 1

primary shard 2

replica shard 3

primaryshard 3

primaryshard 4

replica shard 5

replica shard 2

primary shard 5

replica shard 4

replica shard 1

Page 13: Introduction to Elasticsearch

How to use Elasticsearch?

Application

Database Elasticsearch

Page 14: Introduction to Elasticsearch

http://www.elasticsearch.org/download

Installation

Page 15: Introduction to Elasticsearch

CRUD Operations

Page 16: Introduction to Elasticsearch

Create

curl –XPUT localhost:9200/books/travel/1 –d ‘ { ”title": "Journey's of a Life Time - 500 Best Trips", "author": "National Geographic", "releaseDate": "2013-10-25T19:00" }

Page 17: Introduction to Elasticsearch

Get

Page 18: Introduction to Elasticsearch

Mapping

Page 19: Introduction to Elasticsearch

Update

Page 20: Introduction to Elasticsearch

Concurrency Control

Document , version 1

Document , version 2

Document , version 2

FAIL

SUCCESS

Page 21: Introduction to Elasticsearch

Delete

Page 22: Introduction to Elasticsearch

§ 

§ § § § § § 

Search

Page 23: Introduction to Elasticsearch

Search

Page 24: Introduction to Elasticsearch

Query Search & Pagination

Page 25: Introduction to Elasticsearch

Search

Page 26: Introduction to Elasticsearch

Analyzers

Character Filtering

Tokenizer

Lowercase

Stopwords

Synonyms

“I Love to Travel & Work.”

Analyzed Data

“I Love to Travel and Work”

“I”, “Love”, “to”, “Travel”, “and”, “Work”

“i”, “love”, “to”, “travel”, “and”, “work”

“i”, “love”, “travel”, “work”

“i”, “like”, “travel”, “work”

Page 27: Introduction to Elasticsearch

Inverted Index

Terms Documents Frequencies

i id1 id1 -> 1

like id1, id3 id1 -> 1, id3 -> 5

travel id1, id2 id1 -> 3, id2 -> 2

work id2, id3, id5 id2 -> 3, id3 -> 1, id5 -> 2

Page 28: Introduction to Elasticsearch

Inverted Index An inverted index is a data structure that maps a word to a document.

Page 29: Introduction to Elasticsearch

Full Text Search "author": { "type": "string” “index”: “analyzed”, “analyzer”: “french” }

Exact String Search "author": { "type": "string” “index”: “not_analyzed” }

Not Searchable "author": { "type": "string” “index”: “no” } }

Analyzers available in Elasticsearch

Page 30: Introduction to Elasticsearch

§ § § § 

Types of Queries

Page 31: Introduction to Elasticsearch

Request with Query & Filters

Page 32: Introduction to Elasticsearch

Filters vs Queries exact match full text search

binary yes/no relevance scoring

fast relatively slow

cacheable not cacheable

Page 33: Introduction to Elasticsearch

§ 

§ 

Aggregations

Page 34: Introduction to Elasticsearch

Handling Typos with N-Grams

Uni-gram = e, l, a, s, t, i, c

Bi-gram = el, la, as, st, ti, ic

Tri-gram = ela, las, ast, sti, tic

Page 35: Introduction to Elasticsearch

Handling Typos with N-Grams

Page 36: Introduction to Elasticsearch

Autocomplete with Edge Grams

Search Results

travel

training

transfer

Page 37: Introduction to Elasticsearch

§ § § § § 

§ § § 

§ § 

Battle Tested Lessons

Page 38: Introduction to Elasticsearch

§ § § § § § § § 

Battle Tested Lessons contd..

Page 39: Introduction to Elasticsearch

Let’s Connect

Page 40: Introduction to Elasticsearch