Share
Embed
Elasticsearch for Pharo Smalltalk
Elasticsearch for Pharo Smalltalk. Smalltalkで全文検索
newapplesho
January 29, 2016
Transcript
36 slides
-
Elasticsearch for Pharo Smalltalk SmalltalkͰશจݕࡧ Sho Yoshida / @newapplesho SORABITO
Inc. 2016/01/29 ୈ84ճSmalltalkษڧձ -
About • Sho Yoshida • SORABITO Inc. Ͱಇ͍͍ͯ·͢ • ಇ͘ػցͷࠃࡍΦϯϥΠϯऔҾॴ
ALLSTOCKER ( https://allstocker.com) Λ࡞͍ͬͯ ·͢ -
Elasticsearchͱ • Apache LuceneϕʔεͷશจݕࡧΤϯδϯɺ ղੳαʔόʔ • εΩʔϚϨεɺυΩϡϝϯτࢦ • RESTͰૢ࡞Ͱ͖Δ •
ΫϥελϦϯάఆ͍ͯ͠ΔͷͰɺجຊతͳઃఆ༰қʁ • ϥΠηϯε Apache License v2 • JavaͰ࣮ • ϑΝηοτɺϋΠϥΠτݕࡧՄೳ -
σʔλߏ RDB = Database -> Tables -> Rows -> Columns
ElasticSearch = Index -> Types -> Documents -> Fields ͦͦશ͘͜ͱͳΔͷͰൺΔͷมͰ͕͢ɾɾɾɾ -
Elasticsearch for Pharo Smalltalk • Paul DeBruicker ͕࡞ͬͨElasticsearchͷϑΥʔΫϓϩδΣΫτ • http://ss3.gemtalksystems.com/ss/Elasticsearch.html
• ࡞ऀ: @umejava, @newapplesho • ࠷৽ϦϙδτϦGitHub • https://github.com/newapplesho/elasticsearch-smalltalk • Elasticsearch version 1ܥαϙʔτɻ2ܥະରԠ -
ىಈ֬ೝ $ curl localhost:9200 { "status" : 200, "name" :
"Lilandra Neramani", "cluster_name" : "elasticsearch", "version" : { "number" : "1.7.2", "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec", "build_timestamp" : "2015-09-14T09:49:53Z", "build_snapshot" : false, "lucene_version" : "4.10.4" }, "tagline" : "You Know, for Search" } -
elasticsearch for Pharo SmalltalkΛinstall Gofer new url: 'http://ss3.gemtalksystems.com/ss/Elasticsearch'; package: 'ConfigurationOfElasticsearch';
load. (Smalltalk at: #ConfigurationOfElasticsearch) load. Metacello new baseline: 'Elasticsearch'; repository: 'github://newapplesho/elasticsearch-smalltalk:v1.1.3/pharo-repository'; load. ·ͨ -
,VSPNPKJͷಈ࡞֬ೝ݁Ռ { "tokens" : [ { "token" : "༉ѹ", "start_offset"
: 0, "end_offset" : 2, "type" : "word", "position" : 1 }, { "token" : "γϣϕϧ", "start_offset" : 2, "end_offset" : 6, "type" : "word", "position" : 2 }, { "token" : "", "start_offset" : 6, "end_offset" : 7, "type" : "word", "position" : 3 }, { "token" : "ݐઃ", "start_offset" : 7, "end_offset" : 9, "type" : "word", "position" : 4 }, { "token" : "ػց", "start_offset" : 9, "end_offset" : 11, "type" : "word", "position" : 5 } ] } -
Sample Data "properties": { "title": { "type": "string", "store": "yes",
"index": "not_analyzed" }, "description": { "type": "string", "store": "yes", "index": "analyzed" }, "price": { "type": "integer", "store": "yes" } -
Sample (Seaside Example Sushi Store) #('Akami Maguro' 'Red Tuna' 'The
lean meat near the spine of the tuna fish. It comes in various shades of red--with the lighter, shinier varieties being the best. For dieters, however, the redder the better. Easy on the palatte. The least expensive of the thre types of maguro.' 150) -
υΩϡϝϯτͷՃ neta := JsonObject new. neta title:'Aji'; description:'This fish is
pink-grey and shiny. When it''s fresh, the flesh is almost transparent. The texture is slippery and easy on the tongue--it should melt in your mouth. Aji is often eaten with soy sauce containing onion, ginger and garlic.' esDocument := ESDocument new type:'store'; content: neta. index addDocument: esDocument. -
શ݅ݕࡧ "Match All" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new; index: index. query := ESMatchAllQuery new. search query: query. results := search search. results explore. -
શ݅ݕࡧʢϖʔδϯάʣ "Match All" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new index: index. query := ESMatchAllQuery new. search query: query. results := search searchFrom: 0 size:2. results explore. -
Match Query "Match" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new; index: index. query := ESMatchQuery new. query query:'aji'. search query: query. results := search search. results explore. -
Term Query "ESTermQuery" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new index: index. query := ESTermQuery new field:'title'; query:'Aji'. search query: query. results := search search. results explore. -
ιʔτ "sort" index := ESIndex indexNamed: 'st_study'. search := ESSearch
new; index: index. query := ESTermQuery new field:'title'; query:'Aji'. sort := ESSortCriteria new fieldName: 'title'; sortDescending; yourself. search query: query. search addSortCriteria: sort. results := search search. results explore. -
Aggregations "min Aggregations" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new; index: index. query := ESMatchAllQuery new. aggregation := ESMinAggregation new field:'price'. search query: query. search addAggregation: aggregation. result := search aggregate. -
Aggregations "max Aggregations" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new; index: index. query := ESMatchAllQuery new. aggregation := ESMaxAggregation new field:'price'. search query: query. search addAggregation: aggregation. result := search aggregate. -
Aggregations "avg Aggregations" index := ESIndex indexNamed: 'st_study'. search :=
ESSearch new; index: index. query := ESMatchAllQuery new. aggregation := ESAvgAggregation new field:'price'. search query: query. search addAggregation: aggregation. result := search aggregate.