Slide 1

Slide 1 text

Get Started Ken Collins, March 14th 2013 ElasticSearch 1

Slide 2

Slide 2 text

Today’s Topics • About ElasticSearch 2

Slide 3

Slide 3 text

Today’s Topics • About ElasticSearch • Ruby Libraries 2

Slide 4

Slide 4 text

Today’s Topics • About ElasticSearch • Ruby Libraries • How You Might Use ElasticSearch 2

Slide 5

Slide 5 text

Today’s Topics • About ElasticSearch • Ruby Libraries • How You Might Use ElasticSearch • Other Uses 2

Slide 6

Slide 6 text

3 About ElasticSearch

Slide 7

Slide 7 text

About ElasticSearch 4

Slide 8

Slide 8 text

About ElasticSearch 4 http://www.elasticsearch.org

Slide 9

Slide 9 text

About ElasticSearch 5

Slide 10

Slide 10 text

About ElasticSearch • Painless Setup & Use 5

Slide 11

Slide 11 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented 5

Slide 12

Slide 12 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. 5

Slide 13

Slide 13 text

$ curl -XPOST http://localhost:9200/twitter/tweet/1 -d '{ "user": "metaskills", "post_date": "2013-03-07T13:12:00", "message": "Trying out elasticsearch" }' About ElasticSearch 6

Slide 14

Slide 14 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. 7

Slide 15

Slide 15 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. –Schema mappings. 7

Slide 16

Slide 16 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. –Schema mappings. • Build For The Cloud. Multi-Tenant. 7

Slide 17

Slide 17 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. –Schema mappings. • Build For The Cloud. Multi-Tenant. –Not coupled to a database. 7

Slide 18

Slide 18 text

Index => Database Mappings/Document => Table Fields/Values => Columns/Row About ElasticSearch 8

Slide 19

Slide 19 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. –Schema mappings. • Build For The Cloud. Multi-Tenant. –Not coupled to a database. 9

Slide 20

Slide 20 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. –Schema mappings. • Build For The Cloud. Multi-Tenant. –Not coupled to a database. –Distributed Nodes & Shards 9

Slide 21

Slide 21 text

About ElasticSearch • Painless Setup & Use • Schema Free & Documented Oriented –Index data using JSON over HTTP. –Schema mappings. • Build For The Cloud. Multi-Tenant. –Not coupled to a database. –Distributed Nodes & Shards –Gateway - Time Machine For Search. 9

Slide 22

Slide 22 text

About ElasticSearch • Great Features 10

Slide 23

Slide 23 text

About ElasticSearch • Great Features –Facets 10

Slide 24

Slide 24 text

About ElasticSearch • Great Features –Facets –Highlighting 10

Slide 25

Slide 25 text

About ElasticSearch • Great Features –Facets –Highlighting –Geo Location 10

Slide 26

Slide 26 text

About ElasticSearch • Great Features –Facets –Highlighting –Geo Location –Custom Scripts 10

Slide 27

Slide 27 text

About ElasticSearch • Great Features –Facets –Highlighting –Geo Location –Custom Scripts • Open Source 10

Slide 28

Slide 28 text

About ElasticSearch • Great Features –Facets –Highlighting –Geo Location –Custom Scripts • Open Source –Apache 2 License 10

Slide 29

Slide 29 text

About ElasticSearch • Great Features –Facets –Highlighting –Geo Location –Custom Scripts • Open Source –Apache 2 License –Hosted On Github 10

Slide 30

Slide 30 text

ElasticSearch Guides 11

Slide 31

Slide 31 text

http://www.elasticsearch.org/guide/reference/api/index_.html http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html ElasticSearch Guides (Index) 12

Slide 32

Slide 32 text

$ curl -XPUT http://localhost:9200/twitter/tweet/1 -d '{ "user": "metaskills", "post_date": "2013-03-07T13:12:00", "message": "Trying out elasticsearch" }' ElasticSearch Guides (Index) 13 $ curl -XPOST http://localhost:9200/twitter/ -d '{ "settings": {"number_of_shards": 10}, "mappings": { "twitter_card": { "_source": {"enabled": false}, "properties": { "title": {"type": "string", "index": "not_analyzed"} } } } }' “1” Left off for auto ID.

Slide 33

Slide 33 text

http://www.elasticsearch.org/guide/reference/mapping/ http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html ElasticSearch Guides (Mappings) 14

Slide 34

Slide 34 text

ElasticSearch Guides (Mappings) 15 “Mapping is the process of defining how a document should be mapped to the Search Engine, including its searchable characteristics such as which fields are searchable and if or how they are tokenized.” $ curl -XPUT http://localhost:9200/twitter/tweet/_mapping -d '{ "tweet": { "properties": { "message": {"type": "string", "store": "yes"} } } }'

Slide 35

Slide 35 text

http://www.elasticsearch.org/guide/reference/index-modules/analysis/ ElasticSearch Guides (Analysis) 16

Slide 36

Slide 36 text

“The Brown-Cow's Part_No. #A.BC123-456 [email protected]” ElasticSearch Guides (Analysis) 17 keyword: The Brown-Cow's Part_No. #A.BC123-456 [email protected] whitespace: The, Brown-Cow's, Part_No., #A.BC123-456, [email protected] simple: the, brown, cow, s, part, no, a, bc, joe, bloggs, com standard: brown, cow's, part_no, a.bc123, 456, joe, bloggs.com snowball (English): brown, cow, part_no, a.bc123, 456, joe, bloggs.com

Slide 37

Slide 37 text

ElasticSearch Guides (Analysis) 18 • Analyzers • Standard • Simple • Whitespace • Stop • Keyword • Pattern • Language • Snowball • Custom • Tokenizers • Edge NGram • Keyword • Letter • Lowercase • NGram • Standard • Whitespace • Pattern • UAX URL Email • Path Hierarchy • Token Filter • Standard • ASCII Folding • Length • Lowercase • NGram • Edge NGram • Porter Stem • Shingle • Stop • Word Delimiter • Stemmer • Stemmer Ovrd. • Keyword Mkr. • KStem • Snowball • Phonetic • Synonym • Compound Word • Reverse • Elision • Truncate • Unique • Pattern Replace • Trim • Char Filter • Mapping • HTML Strip • Plugin • ICU

Slide 38

Slide 38 text

ElasticSearch Guides (Analysis) 18 • Analyzers • Standard • Simple • Whitespace • Stop • Keyword • Pattern • Language • Snowball • Custom • Tokenizers • Edge NGram • Keyword • Letter • Lowercase • NGram • Standard • Whitespace • Pattern • UAX URL Email • Path Hierarchy • Token Filter • Standard • ASCII Folding • Length • Lowercase • NGram • Edge NGram • Porter Stem • Shingle • Stop • Word Delimiter • Stemmer • Stemmer Ovrd. • Keyword Mkr. • KStem • Snowball • Phonetic • Synonym • Compound Word • Reverse • Elision • Truncate • Unique • Pattern Replace • Trim • Char Filter • Mapping • HTML Strip • Plugin • ICU

Slide 39

Slide 39 text

ElasticSearch Guides (Analysis) 18 • Analyzers • Standard • Simple • Whitespace • Stop • Keyword • Pattern • Language • Snowball • Custom • Tokenizers • Edge NGram • Keyword • Letter • Lowercase • NGram • Standard • Whitespace • Pattern • UAX URL Email • Path Hierarchy • Token Filter • Standard • ASCII Folding • Length • Lowercase • NGram • Edge NGram • Porter Stem • Shingle • Stop • Word Delimiter • Stemmer • Stemmer Ovrd. • Keyword Mkr. • KStem • Snowball • Phonetic • Synonym • Compound Word • Reverse • Elision • Truncate • Unique • Pattern Replace • Trim • Char Filter • Mapping • HTML Strip • Plugin • ICU

Slide 40

Slide 40 text

http://www.elasticsearch.org/guide/reference/api/search/ ElasticSearch Guides (Search API) 19

Slide 41

Slide 41 text

http://www.elasticsearch.org/guide/reference/query-dsl/ ElasticSearch Guides (Query DSL) 20

Slide 42

Slide 42 text

ElasticSearch Guides (Query DSL) 21 • Queries • match • multi_match • bool • boosting • ids • custom_score • custom_boost_factor • constant_score • dis_max • field • filtered • flt • flt_field • fuzzy • has_child • has_parent • match_all • mlt • mlt_field • prefix • query_string • range • span_first • span_near • span_not • span_or • span_term • term • terms • top_children • wildcard • nested • custom_filters_score • indices • text • geo_shape • Filters • and • bool • exists • ids • limit • type • geo_bbox • geo_distance • geo_distance_range • geo_polygon • geo_shape • has_child • has_parent • match_all • missing • not • numeric_range • or • prefix • query • range • script • term • terms • nested

Slide 43

Slide 43 text

ElasticSearch Guides (Query DSL) 21 • Queries • match • multi_match • bool • boosting • ids • custom_score • custom_boost_factor • constant_score • dis_max • field • filtered • flt • flt_field • fuzzy • has_child • has_parent • match_all • mlt • mlt_field • prefix • query_string • range • span_first • span_near • span_not • span_or • span_term • term • terms • top_children • wildcard • nested • custom_filters_score • indices • text • geo_shape • Filters • and • bool • exists • ids • limit • type • geo_bbox • geo_distance • geo_distance_range • geo_polygon • geo_shape • has_child • has_parent • match_all • missing • not • numeric_range • or • prefix • query • range • script • term • terms • nested

Slide 44

Slide 44 text

Followup Resources 22 Clinton Gormley @clintongormley Terms of Endearment http://www.slideshare.net/clintongormley/terms-of-endearment-the-elasticsearch-query-dsl-explained Cool, Bonsai, Cool http://www.slideshare.net/clintongormley/cool-bonsai-cool-an-introduction-to-elasticsearch

Slide 45

Slide 45 text

23 Ruby Libraries

Slide 46

Slide 46 text

23 Ruby Libraries

Slide 47

Slide 47 text

Ruby Libraries (Tire) 24

Slide 48

Slide 48 text

Ruby Libraries (Tire) 24 • DSL To ElasticSearch

Slide 49

Slide 49 text

Ruby Libraries (Tire) 24 • DSL To ElasticSearch • Declarative Block or Imperative Style

Slide 50

Slide 50 text

Tire.index 'articles' do delete create :mappings => { :article => { :properties => { :id => { :type => 'string', :index => 'not_analyzed' }, :title => { :type => 'string', :boost => 2.0 }, :tags => { :type => 'string', :analyzer => 'keyword' }, :content => { :type => 'string', :analyzer => 'snowball' } } } } store :title => 'One', :tags => ['ruby'] store :title => 'Two', :tags => ['ruby', 'python'] store :title => 'Three', :tags => ['java'] refresh end Ruby Libraries (Tire) 25

Slide 51

Slide 51 text

index = Tire::Index.new('oldskool') index.delete index.create index.store :title => "Let's do it the old way!" index.refresh Ruby Libraries (Tire) 26

Slide 52

Slide 52 text

Ruby Libraries (Tire) 27 • DSL To ElasticSearch • Declarative Block or Imperative Style

Slide 53

Slide 53 text

Ruby Libraries (Tire) 27 • DSL To ElasticSearch • Declarative Block or Imperative Style • ActiveModel Integration

Slide 54

Slide 54 text

class Article < ActiveRecord::Base include Tire::Model::Search include Tire::Model::Callbacks mapping do indexes :id, :index => :not_analyzed indexes :title, :analyzer => 'snowball', :boost => 100 indexes :content, :analyzer => 'snowball' indexes :content_size, :as => 'content.size' indexes :author, :analyzer => 'keyword' indexes :published_on, :type => 'date', :include_in_all => false end after_save { update_index if state == 'published' } def to_indexed_json attributes.slice(...).to_json end end Ruby Libraries (Tire) 28

Slide 55

Slide 55 text

Ruby Libraries (Tire) 28

Slide 56

Slide 56 text

Ruby Libraries (Tire) 29 • DSL To ElasticSearch • Declarative Block or Imperative Style • ActiveModel Integration

Slide 57

Slide 57 text

Ruby Libraries (Tire) 29 • DSL To ElasticSearch • Declarative Block or Imperative Style • ActiveModel Integration • Contributed Components Gem

Slide 58

Slide 58 text

Tire.search 'articles' do query { string 'title:T*' } filter :terms, :tags => ['ruby'] sort { by :title, 'desc' } facet('global-tags', :global => true) { terms :tags } facet('current-tags') { terms :tags } end Ruby Libraries (Tire) 30

Slide 59

Slide 59 text

Tire.search 'articles' do query { string 'title:T*' } filter :terms, :tags => ['ruby'] sort { by :title, 'desc' } facet('global-tags', :global => true) { terms :tags } facet('current-tags') { terms :tags } end Ruby Libraries (Tire) 30 { "fields": ["name", "shortDescription", "longDescription"], "query": { "query_string": { "fields": ["name"], "query": "+camera +laptop", "use_dis_max": true } } }

Slide 60

Slide 60 text

Tire.search({ fields: ["name", "shortDescription", "longDescription"], query: { query_string: { fields: ["name"], query: "+camera +laptop", use_dis_max: true } } }) Ruby Libraries (Tire) 31

Slide 61

Slide 61 text

Ruby Libraries (Tire) 32 • DSL To ElasticSearch • Declarative Block or Imperative Style • ActiveModel Integration • Contributed Components Gem

Slide 62

Slide 62 text

Ruby Libraries (Tire) 32 • DSL To ElasticSearch • Declarative Block or Imperative Style • ActiveModel Integration • Contributed Components Gem • Tire::Search::Search#to_curl

Slide 63

Slide 63 text

https://github.com/karmi/tire https://github.com/karmi/tire-contrib/ Ruby Libraries (Tire) 33

Slide 64

Slide 64 text

How You Might Use ElasticSearch 34

Slide 65

Slide 65 text

How You Might Use ElasticSearch 34 Search Service

Slide 66

Slide 66 text

? Service Usage Concept (service-ext) 35

Slide 67

Slide 67 text

Account Service Usage Concept (service-ext) 35

Slide 68

Slide 68 text

Account Service Usage Concept (service-ext) 35 /search/full_name?query=...

Slide 69

Slide 69 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/full_name?query=...

Slide 70

Slide 70 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/address?query=... /search/full_name?query=...

Slide 71

Slide 71 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search/full_name?query=...

Slide 72

Slide 72 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=...

Slide 73

Slide 73 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=...

Slide 74

Slide 74 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... • Cluster

Slide 75

Slide 75 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... • Cluster • Nodes

Slide 76

Slide 76 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... Index ? Index ? Index ? • Cluster • Nodes

Slide 77

Slide 77 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... Index ? Index ? Index ? • Cluster • Nodes • Settings

Slide 78

Slide 78 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... Index ? Index ? Index ? • Cluster • Nodes • Settings • Storage

Slide 79

Slide 79 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... Index ? Index ? Index ? • Cluster • Nodes • Settings • Storage • Shards

Slide 80

Slide 80 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... Index ? Index ? Index ? • Cluster • Nodes • Settings • Storage • Shards • Replicas

Slide 81

Slide 81 text

Account Service Usage Concept (service-ext) 35 /search/organization?query=... /search/email?query=... /search/address?query=... /search?query=... /search/full_name?query=... Index ? Index ? Index ? • Cluster • Nodes • Settings • Storage • Shards • Replicas

Slide 82

Slide 82 text

Usage Concept (service-ext) 36 /search/full_name?query=...

Slide 83

Slide 83 text

Usage Concept (add-on) 37

Slide 84

Slide 84 text

#2 App /email/search Usage Concept (add-on) 37 #1 Service #2 Service #3 Service /search/full_name /search/address /search/text /search/subjects /search/text /search/full_name /search/address #1 App /articles/search /catalog/search

Slide 85

Slide 85 text

#2 App /email/search Usage Concept (add-on) 38 #1 Service #3 Service /search/full_name /search/address /search/full_name /search/address

Slide 86

Slide 86 text

/search/address /search/full_name /search/full_name /search/address #2 App #1 Service #3 Service /email/search Usage Concept (add-on) 39

Slide 87

Slide 87 text

/full_name /email Account Search /address Usage Concept (lateral-biz-need) 40

Slide 88

Slide 88 text

Account Service /search/full_name /search/email /search/address Usage Concept (lateral-biz-need) 41

Slide 89

Slide 89 text

Account Search /full_name /email /address Usage Concept (lateral-biz-need) 42

Slide 90

Slide 90 text

Account Search /full_name /email /address Usage Concept (lateral-biz-need) 42 Service #1 App #1 App #2 Service #2

Slide 91

Slide 91 text

Account Search /full_name /email /address Usage Concept (lateral-biz-need) 42 Service #1 App #1 App #2 Service #2 Standard Document Representation

Slide 92

Slide 92 text

Usage Concept (lateral-biz-need) 43 #2 App #1 Service #2 Service #3 Service #1 App

Slide 93

Slide 93 text

Usage Concept (lateral-biz-need) 43 #2 App #1 Service #2 Service #3 Service #1 App $ curl -XGET http://localhost:9200/foo,bar/tweet/_search?q=tag:wow

Slide 94

Slide 94 text

Usage Concept (lateral-biz-need) 43 #2 App #1 Service #2 Service #3 Service #1 App $ curl -XGET http://localhost:9200/test/_msearch --data-binary @requests {"index" : "test"} {"query" : {"match_all" : {}}, "from" : 0, "size" : 10} {"index" : "test", "search_type" : "count"} {"query" : {"match_all" : {}}} {} {"query" : {"match_all" : {}}} {"query" : {"match_all" : {}}} {"search_type" : "count"} {"query" : {"match_all" : {}}}

Slide 95

Slide 95 text

Usage Concept (lateral-biz-need) 43 #2 App #1 Service #2 Service #3 Service #1 App http://www.elasticsearch.org/guide/reference/api/search/indices-types.html http://www.elasticsearch.org/guide/reference/api/multi-search.html

Slide 96

Slide 96 text

http://search.mycompany.com/ I’m Feeling Lucky 44

Slide 97

Slide 97 text

ElasticSearch FTW! 45 #2 Service #2 App #1 App #1 Service Search Service #1 #3 Service

Slide 98

Slide 98 text

Now that we got our hands dirty... Other Usages 46

Slide 99

Slide 99 text

http://www.logstash.net Other Usages (logstash) 47

Slide 100

Slide 100 text

http://www.logstash.net/docs/1.1.9/outputs/elasticsearch Other Usages (logstash) 48

Slide 101

Slide 101 text

http://blog.trifork.com/2013/01/10/how-to-write-an-elasticsearch-river-plugin/ Other Usages (rivers) 49

Slide 102

Slide 102 text

http://blog.bugsense.com/post/35580279634/indexing-bigdata-with-elasticsearch Other Usages (big data) 50

Slide 103

Slide 103 text

Get Started Ken Collins, March 14th 2013 Thank You! 51 Go Search