Click here to load reader

Elasticsearch for Pharo Smalltalk

  • View
    1.318

  • Download
    4

Embed Size (px)

Text of Elasticsearch for Pharo Smalltalk

  • Elasticsearch for Pharo Smalltalk

    Smalltalk

    Sho Yoshida / @newapplesho SORABITO Inc.

    2016/01/29 84Smalltalk

  • About Sho Yoshida

    SORABITO Inc.

    ALLSTOCKER ( https://allstocker.com)

    https://allstocker.com

  • 160

  • 75Smalltalk 75Smalltalk

    http://www.smalltalk-users.jp/Home/gao-zhi/dai75kaismalltalkbenkyoukai

    RDS PostgreSQL

    http://www.smalltalk-users.jp/Home/gao-zhi/dai75kaismalltalkbenkyoukai

  • https://www.elastic.co/products/elasticsearch

  • Elasticsearch Apache Lucene

    REST

    Apache License v2

    Java

  • GitHub

    foursquare

    SoundCloud

    stackoverflow

    ALLSTOCKER

  • GitHub

    https://github.com

    https://github.com

  • Elasticsearch ElasticsearchID

    https://speakerdeck.com/johtani/introduction-elasticsearch-and-elk-elasticsearchmian-qiang-hui-in-nagoya

    https://speakerdeck.com/johtani/introduction-elasticsearch-and-elk-elasticsearchmian-qiang-hui-in-nagoya

  • 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 12

    http://ss3.gemtalksystems.com/ss/Elasticsearch.htmlhttps://github.com/newapplesho/elasticsearch-smalltalk

  • Elasticsearch for Pharo Smalltalk

    Aggregation, Query

  • Elasticsearch

    1.wget https://download.elasticsearch.org/.

    2.tar -xf elasticsearch-1.7.2.tar.gz

    3../elasticsearch-1.7.2/bin/elasticsearch

  • Kuromojiinstall

    bin/plugin install elasticsearch/elasticsearch-analysis-kuromoji/2.5.0

  • Elasticsearch-inquisitor

    bin/plugin -install polyfractal/elasticsearch-inquisitor

    http://localhost:9200/_plugin/inquisitor/#/

    Elasticsearch-inquisitor GUIQuery

  • $ 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 Smalltalkinstall

    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.

  • curl -XPUT 'localhost:9200/st_study' -d @sushi.json

  • Kuromoji

    curl -XPOST 'http://localhost:9200/st_study/_analyze?analyzer=analyzer&pretty=true' -d ''

  • Kuromoji { "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 three 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.

  • esDocument := ESDocument new id:'AVKMOVs3-FeOW1ziNoOb'; type:'store'; content: neta. esDocument deleteFromIndex: index.

  • index delete.

  • "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.

  • DEMO

  • Elasticsearch 2.0

  • Smalltalk

    paul bica https://www.flickr.com/photos/dexxus/5820866907/