99
Introduction to ElasticSearch Ashish @ashish_fagna

Introducing ElasticSearch - Ashish

Embed Size (px)

Citation preview

Page 1: Introducing ElasticSearch - Ashish

Introduction to ElasticSearch

Ashish@ashish_fagna

Page 2: Introducing ElasticSearch - Ashish

Elasticsearch real time,search and

analytics engine

Page 3: Introducing ElasticSearch - Ashish

Elasticsearch real

time,search andanalytics

engine

distributed

Page 4: Introducing ElasticSearch - Ashish

real time,search

andanalytics engine

distributed

scalesmassively

Elasticsearch

Page 5: Introducing ElasticSearch - Ashish

Elasticsearch real time,

search andanalytics

engine

distributed

scales massively

high availability

Page 6: Introducing ElasticSearch - Ashish

Elasticsearchreal time,

search andanalytics engine

distributed

scales massively high availability

RESTful API

Page 7: Introducing ElasticSearch - Ashish

Elasticsearchreal time,

search andanalytics engine

distributed

scales massively high availability

RESTful API

JSONover HTTP

Page 8: Introducing ElasticSearch - Ashish

Elasticsearchreal time,

search and distributed

scales massively high availability

RESTful API

JSONover HTTP

schema analytics engine

free

Page 9: Introducing ElasticSearch - Ashish

Elasticsearchreal time,

search andanalytics engine

distributed

scales massively

RESTful API

JSONover HTTP

high availability

schema free

multi tenancy

Page 10: Introducing ElasticSearch - Ashish

Elasticsearchreal time,

search andanalytics engine

distributed

open-source

scalesmassively

RESTful API

JSONover HTTP

high availability

schema free

multi tenancy

Page 11: Introducing ElasticSearch - Ashish

Elasticsearchreal time,

search andanalytics engine

Lucene based

distributed

open-source scalesmassive

ly

RESTful API

JSONover HTTP

high availability

schema free

multi tenancy

Page 12: Introducing ElasticSearch - Ashish

> ./bin/elasticsearch

> _

Page 13: Introducing ElasticSearch - Ashish

Usage

Page 14: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

Page 15: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

verb

Page 16: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

node

Page 17: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

HTTP port

Page 18: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

path

Page 19: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

query string

Page 20: Introducing ElasticSearch - Ashish

> curl -XGET localhost:9200/?pretty

Page 21: Introducing ElasticSearch - Ashish

GET /

Page 22: Introducing ElasticSearch - Ashish

GET /

{Man",for Search",

: "Exploding: "You Know,: true,: 200,: {

"name" "tagline" "ok" "status" "version""number""snapshot_build"

:"0.90.1",

: false}}

Page 23: Introducing ElasticSearch - Ashish

Where do we start?

Page 24: Introducing ElasticSearch - Ashish

With data

Page 25: Introducing ElasticSearch - Ashish

{is AWESOME","tweet":

"nick":"name":"date":"rt" :"loc":"lat":"lon":

"I think #elasticsearch "@ashish", "Ashish K", "2016-01-01",5,{ 13.4,52.5

}

Page 26: Introducing ElasticSearch - Ashish

Saving in ElasticSearch

Page 27: Introducing ElasticSearch - Ashish

PUT /index/type/id

Page 28: Introducing ElasticSearch - Ashish

PUT /index/type/id

where?

Page 29: Introducing ElasticSearch - Ashish

PUT /myapp/type/id

Page 30: Introducing ElasticSearch - Ashish

PUT /myapp/type/id

what?

Page 31: Introducing ElasticSearch - Ashish

PUT /myapp/tweet/id

Page 32: Introducing ElasticSearch - Ashish

PUT /myapp/tweet/id

which?

Page 33: Introducing ElasticSearch - Ashish

PUT /myapp/tweet/1

Page 34: Introducing ElasticSearch - Ashish

PUT /myapp/tweet/1 -d '{

is AWESOME","I think #elasticsearch "@ashish", "Ashish Kumar", "2013-06-03",5,{ 77,13.5

"tweet":"nick":"name":"date":"rt":"loc":"lat":"lon":

}}'

Page 35: Introducing ElasticSearch - Ashish

{"_index":"_type":"_id": "_version": "ok":

"myapp","tweet","1",1,true

}

# 201 CREATED

Page 36: Introducing ElasticSearch - Ashish

Get

Page 37: Introducing ElasticSearch - Ashish

GET /myapp/tweet/1

Page 38: Introducing ElasticSearch - Ashish

{"_index":"_type":"_id": "_version": "exists": "_source":

"myapp","tweet","1",1,true,{...OUR

TWEET... }}

# 200 OK

Page 39: Introducing ElasticSearch - Ashish

Update

Page 40: Introducing ElasticSearch - Ashish

PUT /myapp/tweet/1 -d '{

is AWESOME","I know #elasticsearch "@ashish", "Ashish Kumar", "2016-01-01",5,{ 77,13.5

"tweet":"nick":"name":"date":"rt":"loc":"lat":"lon":

}}'

Page 41: Introducing ElasticSearch - Ashish

{"_index":"_type":"_id": "_version": "ok":

"myapp","tweet","1",2,true

}

# 200 OK

Page 42: Introducing ElasticSearch - Ashish

Delete

Page 43: Introducing ElasticSearch - Ashish

DELETE /myapp/tweet/1

Page 44: Introducing ElasticSearch - Ashish

{"_index": "myapp","_type": "tweet","_id": "1","_version": 3,"ok": true,"found": true

}

# 200 OK

Page 45: Introducing ElasticSearch - Ashish

Cheaper in bulk

Page 46: Introducing ElasticSearch - Ashish

Any datastore

Elasticsearch

Client

Mirror external DB

Page 47: Introducing ElasticSearch - Ashish

Any datastore

Elasticsearch

Client

Standalone

Page 48: Introducing ElasticSearch - Ashish

"Empty" Search

Page 49: Introducing ElasticSearch - Ashish

GET /_search

Page 50: Introducing ElasticSearch - Ashish

GET /_search{

"took" : 2,

}

Page 51: Introducing ElasticSearch - Ashish

GET /_search{

"took" : "timed_out":

2,false,

}

Page 52: Introducing ElasticSearch - Ashish

GET /_search{

2,false,

"took" : "timed_out" : "_shards":{ "total" : 10,

"successful" : 10,"failed" : 0

},

}

Page 53: Introducing ElasticSearch - Ashish

GET /_search{

2,false,

"took" : "timed_out" : "_shards" :{ "total" : 10,

"successful" : 10,"failed" : 0

14,: 1.0,

[ { ... }]

},"hits" : {

"total" :"max_score" "hits" :

}}

Page 54: Introducing ElasticSearch - Ashish

GET /_search

"de","tweet","4",

: {... }, 1.0,

"hits" : [{

"_index" :"_type" :"_id" : "_source""_score"

:},...

]

Page 55: Introducing ElasticSearch - Ashish

Multi-index Multi-type

Page 56: Introducing ElasticSearch - Ashish

GET /index/_search

Page 57: Introducing ElasticSearch - Ashish

GET /index/_search

GET /index1,index2/_search

Page 58: Introducing ElasticSearch - Ashish

GET /index/_search

GET /index1,index2/_search

GET /ind*/_search

Page 59: Introducing ElasticSearch - Ashish

GET /index/_search

GET /index1,index2/_search

GET /ind*/_search

GET /index/type/_search

Page 60: Introducing ElasticSearch - Ashish

GET /index/_search

GET /index1,index2/_search

GET /ind*/_search

GET /index/type/_search

GET /index/type1,type2/_search

Page 61: Introducing ElasticSearch - Ashish

GET /index/_search

GET /index1,index2/_search

GET /ind*/_search

GET /index/type/_search

GET /index/type1,type2/_search

GET /index/type*/_search

Page 62: Introducing ElasticSearch - Ashish

GET /index/_search

GET /index1,index2/_search

GET /ind*/_search

GET /index/type/_search

GET /index/type1,type2/_search

GET /index/type*/_search

GET /_all/type*/_search

Page 63: Introducing ElasticSearch - Ashish

Pagination

Page 64: Introducing ElasticSearch - Ashish

Paginationsize = num of

results

Page 65: Introducing ElasticSearch - Ashish

Paginationsize = num of resultsfrom = results to skip

Page 66: Introducing ElasticSearch - Ashish

GET /_search?size=5&from=0

GET /_search?size=5&from=5

GET /_search?size=5&from=10

Page 67: Introducing ElasticSearch - Ashish

Search Lite

Page 68: Introducing ElasticSearch - Ashish

Search LiteGET /_search?q=name:john

Page 69: Introducing ElasticSearch - Ashish

+tweet:foo +name:john +date:>2013-05-01

Page 70: Introducing ElasticSearch - Ashish

+tweet:foo +name:john +date:>2013-05-01

→ percent encoding →

Page 71: Introducing ElasticSearch - Ashish

+tweet:foo +name:john +date:>2013-05-01

?q=%2Btweet%3Afoo+%2Bname%3Ajohn+%2Bdate%3A%3E2013-05-01

→ percent encoding →

Page 72: Introducing ElasticSearch - Ashish

GET /_search?q=mary

Page 73: Introducing ElasticSearch - Ashish

→ user named "Mary"→ tweets by "Mary"→ tweet mentioning "@mary"

GET /_search?q=mary

Page 74: Introducing ElasticSearch - Ashish

GET /_search?q=_all:mary

→ user named "Mary"→ tweets by "Mary"→ tweet mentioning "@mary"

Page 75: Introducing ElasticSearch - Ashish

_all fieldstring values

from all other fields

Page 76: Introducing ElasticSearch - Ashish

GET /_search?q=2016

Page 77: Introducing ElasticSearch - Ashish

GET /_search?q=2016

GET /_search?q=2016-01-01

Page 78: Introducing ElasticSearch - Ashish

GET /_search?q=2016

GET /_search?q=2016-01-03

GET /_search?q=date:2016-01-03

GET /_search?q=date:2016

Page 79: Introducing ElasticSearch - Ashish

datatype differences?

Page 80: Introducing ElasticSearch - Ashish

check "mapping"(field definitions)

Page 81: Introducing ElasticSearch - Ashish

GET /myapp/tweet/_mapping

Page 82: Introducing ElasticSearch - Ashish

GET /myapp/tweet/_mapping{"tweet" : {

"properties" :{"tweet" : { "type" : "string" },

"name" : { "type" : "string" },"nick" : { "type" : "string" },"date" : { "type" : "date" },"rt" : { "type" : "long" },

: "double" },: "double" }

"loc" : {"type": "object", "properties" :

{"lat" : {"type""lon" : {"type"

}}

}}}

Page 83: Introducing ElasticSearch - Ashish

date = type:date_all = type:string

Page 84: Introducing ElasticSearch - Ashish

normalize terms

Page 85: Introducing ElasticSearch - Ashish

"Analysis"

Page 86: Introducing ElasticSearch - Ashish

"Analysis"tokenization + normalization

Page 87: Introducing ElasticSearch - Ashish

"Analysers"tokenizer + token

filters

Page 88: Introducing ElasticSearch - Ashish

standard analyzer

"The Quick Brown Fox jumped

over the Lazy Dog!"

Page 89: Introducing ElasticSearch - Ashish

standard analyzer→ standard tokenizer

"The Quick Brown Fox jumped

over the Lazy Dog!"

Page 90: Introducing ElasticSearch - Ashish

standard analyzer→ standard tokenizer

The,Quick,Brown,Fox,jumped,

over,the,Lazy,Dog

Page 91: Introducing ElasticSearch - Ashish

standard analyzer→ standard tokenizer→ lowercase filter

The,Quick,Brown,Fox,jumped,

over,the,Lazy,Dog

Page 92: Introducing ElasticSearch - Ashish

standard analyzer→ standard tokenizer→ lowercase filter

the,quick,brown,fox,jumped,

over,the,lazy,dog

Page 93: Introducing ElasticSearch - Ashish

standard analyzer→ standard tokenizer→ lowercase filter→ stopwords filter

the,quick,brown,fox,jumped,

over,the,lazy,dog

Page 94: Introducing ElasticSearch - Ashish

standard analyzer→ standard tokenizer→ lowercase filter→ stopwords filter

,quick,brown,fox,jumped,

over, ,lazy,dog

Page 95: Introducing ElasticSearch - Ashish

english analyzer→ standard tokenizer→ lowercase filter

the,quick,brown,fox,jumped,

over,the,lazy,dog

Page 96: Introducing ElasticSearch - Ashish

Analyzer

Page 97: Introducing ElasticSearch - Ashish

{

"type" : "string""type" : "string"

},},

"string", "not_analyzed"

{ "type"{ "type"{ "type"

: "date" },: "long" },: "geo_point" }

"tweet" : { "properties" :

{"tweet" :

{"name" :

{"nick" :

{"type"

:"index" :

},"date" :"rt" :"loc" :

}}}

Page 98: Introducing ElasticSearch - Ashish

{"tweet" : {

"properties" :{

"tweet" :

{"type" :

"string","analyzer" : "english"

},},"name" :"nick" :

"type" "index"

{ "type" : "string"{::"string", "not_analyzed"

},"date" :"rt" :

{{"type" :"type" :

"date""long"

},},

}}}"loc" : { "type" : "geo_point" }

Page 99: Introducing ElasticSearch - Ashish

Thank You