Slide 1

Slide 1 text

explore your data with elasticsearch Honza Král @honzakral

Slide 2

Slide 2 text

REST HTTP JSON distributed search analytics real-time scalable open-source Lucene …

Slide 3

Slide 3 text

setup # wget elasticsearch.tar.gz # tar xzvf elasticsearch.tar.gz # bin/elasticsearch # curl localhost:9200

Slide 4

Slide 4 text

documents # curl -XPUT localhost:9200/stack/question/42 -d '{ “some”: “json” }' # curl -XGET localhost:9200/stack/question/42 # curl -XDELETE localhost:9200/stack/question/42

Slide 5

Slide 5 text

search # curl -XGET localhost:9200/_search?q=meetup # curl -XGET localhost:9200/_search -d '{ “query”: { “query_string”: { “query”: “meetup AND title:python” } } }'

Slide 6

Slide 6 text

queries & filters # curl -XGET localhost:9200/stack/_search -d '{ “query”: { “filtered”: { “query”: { “bool”: { “must”: [ {"multi_match": { "fields": ["title^10", "body"] "query": "python" }}, ], “must_not”: [ {“match”: {“title”: “php”} ] } }, “filter”: { “range”:{"creation_date":{"from":"2013-01-01"}} } } } }'

Slide 7

Slide 7 text

filter when you can, query if you must

Slide 8

Slide 8 text

facets # curl -XGET localhost:9200/meetup/_search -d '{ “query”: { ... }, “facets”: { “monthly_meetups”: { “date_histogram”: { “field”: “event_date”, “interval”: “month” } }, “attendees_per_topic”: { “terms_stats”: { “key_field”: “topic”, “value_script”: “doc['users'].values.length” } } } }'

Slide 9

Slide 9 text

mix & match curl -XGET http://localhost:9200/dba.stackexchange.com/question/_search -d ' { "query": { "custom_score": { "query": { "filtered": { "query": { "bool": { "must": [ {"multi_match": {"fields": ["title^10", "body"], "query": "mysql"}}, { "has_child": { "child_type": "answer", "query": {"match": {"body": "nosql"}} } } ], "must_not": [ {"multi_match": {"fields": ["title", "body"], "query": "nosql"}} ] } }, "filter": { "range": {"creation_date": {"from": "2012-01-01"}} } } }, "script": "(_score + 1) * doc[\"rating\"].value" } }, "fields": ["title", "rating", "creation_date"], "highlight": { "fields": { "title": {"fragment_size" : 50}, "body": {"fragment_size" : 50} } }, "facets": { "tags": { "terms": {"field": "tags"} }, "frequency": { "date_histogram": {"field": "creation_date", "interval": "month"} } } }' Find questions that • Were asked last year • Contain “mysql” in title or body • Don't contain “nosql” • Have answer that has “nosql” in title or body • Include question rating into score calculation • Highlight matches in html • Aggregate over time and tags • ….

Slide 10

Slide 10 text

Let us pray to the demo gods!

Slide 11

Slide 11 text

percolator # curl -XPUT localhost:9200/_percolator/stack/meet -d '{ "query" : { "term" : { "tile" : "meetup" } } }' # curl -XPUT localhost:9200/stack/question/_percolate -d '{ “doc”: { “title”: “SF Python Meetup” } }'

Slide 12

Slide 12 text

suggester – auto-complete # curl -X POST 'localhost:9200/music/_suggest' -d '{ "song-suggest" : { "text" : "n", "completion" : { "field" : "song_suggest" } } }' { "text" : "Nirvana - Nevermind", "score" : 34.0, "payload" : {"artist_id":2321} }

Slide 13

Slide 13 text

suggester – did you mean? # curl -XPOST 'localhost:9200/_search' -d { "suggest" : { "text" : "Johny Walker", "simple_phrase" : { "phrase" : { ... MAGIC HERE ... "direct_generator" : [ { "field" : "body" } ] } } } }' { "text" : "Johnnie Walker", "score" : 0.314295 }

Slide 14

Slide 14 text

Is it web scale?

Slide 15

Slide 15 text

YES!

Slide 16

Slide 16 text

distributed model

Slide 17

Slide 17 text

Thanks!