SlideShare a Scribd company logo
ELASTICSEARCH
                          實戰介紹
               Kang-min Liu <gugod@gugod.org>




13年4月20日星期六
ELASTICSEARCH

        Distributed (Near) Real Time Search Engine

        RESTful 風,Lucene 骨,NoSQL 系

        elasticsearch.org

              https://github.com/elasticsearch/elasticsearch

        elasticsearch.com



13年4月20日星期六
名詞對照

              Relational DB   ElasticSearch

                database         index

                  table           type

                  row          document

                column            field

                schema          mapping

                 index           (全部)

                  SQL          query DSL


13年4月20日星期六
CREATE


      curl -XPOST http://localhost:9200/social/tweet/1 -d '{

         content: "大家好"

         user_name: "gugod"

      }'




13年4月20日星期六
CREATE


      curl -XPOST http://localhost:9200/social/tweet/1 -d '{

         content: "大家好"

         user_name: "gugod"

      }'




13年4月20日星期六
CREATE

      curl -XPOST http://localhost:9200/social/tweet/1 -d '{
         content: "大家好"

         user: {
              name: "gugod",
              id: 385782393,
         },
         tag: ["osdctw", "demo", "moedict"]
      }'




13年4月20日星期六
CREATE
                                                type


      curl -XPOST http://localhost:9200/social/tweet/1 -d '{

         content: "大家好"
                                        index
         user_name: "gugod"

      }'




13年4月20日星期六
READ



      curl -XGET http://localhost:9200/social/tweet/1




13年4月20日星期六
UPDATE


      curl -XPUT http://localhost:9200/social/tweet/1 -d '{

         content: "大家好"

         user_name: "gugod"

      }'




13年4月20日星期六
DELETE



      curl -XDELETE http://localhost:9200/social/tweet/1




13年4月20日星期六
SEARCH

      $ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
          "query": {
              "filtered" : {
                  "query" : {
                      "query_string" : {
                          "query" : "some query string here"
                      }
                  },
                  "filter" : {
                      "term" : { "user" : "kimchy" }
                  }
              }
          }
      }                                  query DSL
      '




13年4月20日星期六
SEARCH



      $ curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{
          "query": { "term" : { "user" : "kimchy" } }
      }
      '




13年4月20日星期六
SEARCH



      $ curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=nihao'




13年4月20日星期六
搜尋引擎原理



13年4月20日星期六
Inverted index 反向索引

              term → id

        Relevance Scoring 分數




13年4月20日星期六
輸入文件

    延展性: 物質具延長及展開的性質,稱為「延展性」。為大多數金屬之特性。

    延平郡王: 明   成功的封號。

    延年益壽: 延長壽命,多為頌祝人長壽的用詞。

    延性: 物質可延長為細絲的性質,稱為「延性」。材料在破壞之前,呈現塑性變形的程
    度。延性可用拉力試驗中的伸長率及斷面縮率表示之。

    延緩: 延遲、延後。




13年4月20日星期六
TOKENIZATION
    延 展 性 物 質 具 延 長 及 展 開 的 性 質 稱 為 延 展 性 為 大 多 數 金 屬 之
    特 性

    延 平 郡 王 明     成 功 的 封 號

    延 年 益 壽 延 長 壽 命 多 為 頌 祝 人 長 壽 的 用 詞

    延 性 物 質 可 延 長 為 細 絲 的 性 質 稱 為 延 性 材 料 在 破 壞 之 前 呈 現
    塑 性 變 形 的 程 度 延 性 可 用 拉 力 試 驗 中 的 伸 長 率 及 斷 面 縮 率 表
    示 之

    延 緩 延 遲 延 後




13年4月20日星期六
TOKENIZATION
    延展性: 物質 質具 具延 延長 長及 及展 展開 開的 的性 性質 稱為 延展 展性 為大
    大多 多數 數金 金屬 屬之 之特 特性

    延平郡王: 明     成 成功 功的 的封 封號

    延年益壽: 延長 長壽 壽命 多為 為頌 頌祝 祝人 人長 長壽 壽的 的用 用詞

    延性: 物質 質可 可延 延長 長為 為細 細絲 絲的 的性 性質 稱為 延性 材料 料在 在
    破 破壞 壞之 之前 呈現 現塑 塑性 性變 變形 形的 的程 程度 延性 性可 可用 用拉
    拉力 力試 試驗 驗中 中的 的伸 伸長 長率 率及 及斷 斷面 面縮 縮率 率表 表示 示之

    延緩: 延遲 延後




13年4月20日星期六
搜尋:延長
    延展性: 物質 質具 具延 延長 長及 及展 展開 開的 的性 性質 稱為 延展 展性 為大
    大多 多數 數金 金屬 屬之 之特 特性

    延平郡王: 明     成 成功 功的 的封 封號

    延年益壽: 延長 長壽 壽命 多為 為頌 頌祝 祝人 人長 長壽 壽的 的用 用詞

    延性: 物質 質可 可延 延長 長為 為細 細絲 絲的 的性 性質 稱為 延性 材料 料在 在
    破 破壞 壞之 之前 呈現 現塑 塑性 性變 變形 形的 的程 程度 延性 性可 可用 用拉
    拉力 力試 試驗 驗中 中的 的伸 伸長 長率 率及 及斷 斷面 面縮 縮率 率表 表示 示之

    延緩: 延遲 延後




13年4月20日星期六
給分
    延展性: 物質 質具 具延 延長 長及 及展 展開 開的 的性 性質 稱為 延展 展性 為大
    大多 多數 0.5 金屬 屬之 之特 特性
          數金

    延平郡王: 明     成 成功 功的 的封 封號

                0.7
    延年益壽: 延長 長壽 壽命 多為 為頌 頌祝 祝人 人長 長壽 壽的 的用 用詞

    延性: 物質 質可 可延 延長 長為 為細 細絲 絲的 的性 性質 稱為 延性 材料 料在 在
          0.3
    破 破壞 壞之 之前 呈現 現塑 塑性 性變 變形 形的 的程 程度 延性 性可 可用 用拉
    拉力 力試 試驗 驗中 中的 的伸 伸長 長率 率及 及斷 斷面 面縮 縮率 率表 表示 示之

    延緩: 延遲 延後




13年4月20日星期六
給分
        文件的詞數(長度)

        詞在文件內的頻率

        詞在索引內的頻率


        任意指定




13年4月20日星期六
給分
        文件的詞數(長度)

        詞在文件內的頻率

        詞在索引內的頻率


        任意指定




13年4月20日星期六
給分
        文件的詞數(長度)

        詞在文件內的頻率

        詞在索引內的頻率


        任意指定




13年4月20日星期六
給分
        文件的詞數(長度)

        詞在文件內的頻率

        詞在索引內的頻率


        任意指定




13年4月20日星期六
QUERY



13年4月20日星期六
TERM

              {
                  "query": {
                    "term": {
                      "user": "ingy"
                    }
                  }
              }




13年4月20日星期六
TEXT

              {
                  "query": {
                    "text": {
                      "content": "   樣那樣"
                      }
                  }
              }




13年4月20日星期六
TEXT

              {
                  "query": {
                    "text": {
                      "content": "   樣那樣"
                      }
                  }                  樣 樣那 那樣
              }




13年4月20日星期六
RANGE
              {
                  "query": {
                     "range" : {
                        "age" : {
                             "from" : 10,
                             "to" : 20,
                             "include_lower" : true,
                             "include_upper": false,
                             "boost" : 2.0
                        }
                     }
                  }
              }



13年4月20日星期六
QUERY_STRING


          {
              "query": {
                "query_string" : {
                    "query" : " 樣 AND 那樣 OR 怎樣"
                  }
              }
          }




13年4月20日星期六
WILDCARD


          {
              "query": {
                "wildcard" : { "user" : "ki*y" }
              }
          }




13年4月20日星期六
MLT(MORE LIKE THIS)

       {
           "query": {
              "more_like_this" : {
                 "like_text" : " 樣那樣",
                   "min_term_freq" : 1,
                   "max_query_terms" : 12
               }
           }
       }




13年4月20日星期六
萌典 + ES
              https://github.com/g0v/esmoe




13年4月20日星期六
文件結構

         {
          "heteronyms": [
              {
    	
 	
 	
  	
 "bopomofo": "ㄧㄢˊ ㄓㄢˇ ㄒㄧㄥˋ",
    	
 	
 	
  	
 "bopomofo2": "yán jǎn shìng",
                  "definitions": [
                      {
    	
 	
 	
  	
  	
  	
 "def": "物質具延長及展開的性質,稱為「延展性」。為大多
    數金屬之特性。"
                           }
                        ],
    	
   	
   	
   	
   "pinyin": "yán zhǎn xìng"
                   }
              ],
    	
   	
   "title": "延展性"
         },




13年4月20日星期六
正查
     # curl http://localhost:9200/moedict/revised/$(uri_escape 搜)'?pretty=1'
     {
         "_index" : "moedict",
         "_type" : "revised",
         "_id" : "搜",
       "_version" : 1,
       "exists" : true, "_source" : {"non_radical_stroke_count":10,"stroke_count":
     13,"heteronyms":[{"bopomofo":"ㄙㄡ","pinyin":"sōu","bopomofo2":"sōu","definitions":
     [{"quote":["漢書.卷六.武帝紀:「秋,閉城門大搜,發謫戌屯五原。」","聊齋志異.卷一.狐
     嫁女:「已而主人斂酒具,少一爵,冥搜不得。」"],"def":"找尋、尋求。","type":"動"},
     {"example":["如:「搜身」。"],"quote":["元.王實甫.西廂記.第三本.第二折:「不肯搜自
     己狂為,只待要覓別人破綻。」"],"def":"檢查、檢
     點。","type":"動"}]}],"title":"搜","radical":"手"}
     }




13年4月20日星期六
反查(由義查詞)
   # curl --silent http://localhost:9200/moedict/revised/_search
   '?fields=&pretty=1&q='$(uri_escape 找尋) | grep _id
         "_id" : "尋根",
         "_id" : "尋找",
         "_id" : "訪求",
         "_id" : "探礦",
         "_id" : "尋求",
         "_id" : "找尋",
         "_id" : "找機會",
         "_id" : "自找",
         "_id" : "尋樂",
         "_id" : "探索",




13年4月20日星期六
用例句查
   # curl --silent -XPOST http://localhost:9200/moedict/revised/_search'?pretty’
   -d '{query:{text:{example: "紅樓夢" }}}'
   {
       "took" : 8,
       "timed_out" : false,
       "_shards" : {
          "total" : 5,
          "successful" : 5,
          "failed" : 0
       },
       "hits" : {
          "total" : 485,
          "max_score" : 5.116848,
          "hits" : [ {
            "_index" : "moedict",
            "_type" : "revised",
            "_id" : "抄本",
         "_score" : 5.116848, "_source" : {"heteronyms":[{"bopomofo":"ㄔㄠ ㄅㄣ
   ˇ","pinyin":"chāo běn","bopomofo2":"chāu běn","definitions":[{"link":["亦稱為「寫本」、「鈔
   本」。"],"example":["如:「抄本紅樓夢」。"],"synonyms":"手本","def":"手抄的書
   籍。"}]}],"title":"抄本"}
         }, {
           "_index" : "moedict",
           "_type" : "revised",
           "_id" : "一名",
         "_score" : 4.27241, "_source" : {"heteronyms":[{"bopomofo":"ㄧ ㄇㄧㄥˊ","pinyin":"yī
   míng","bopomofo2":"yī míng","definitions":[{"quote":["紅樓夢.第四十八回:「派下薛蟠之乳父
13年4月20日星期六
用引言查
  # curl --silent -XPOST http://localhost:9200/moedict/revised/_search'?pretty'
  -d '{query:{text:{quote: "紅樓夢"}}}'
  {
    "took" : 18,
    "timed_out" : false,
    "_shards" : {
       "total" : 5,
       "successful" : 5,
       "failed" : 0
    },
    "hits" : {
       "total" : 11858,
       "max_score" : 1.7719736,
       "hits" : [ {
         "_index" : "moedict",
         "_type" : "revised",
         "_id" : "原稿",
         "_score" : 1.7719736, "_source" : {"heteronyms":[{"bopomofo":"ㄩㄢˊ ㄍㄠˇ","pinyin":"yuán
  gǎo","bopomofo2":"yuán gǎu","definitions":[{"synonyms":"底稿,稿本,初稿,草稿","quote":["紅樓夢.第五
  回:「說畢,回頭命小鬟取了『紅樓夢』原稿來,遞與寶玉。」"],"def":"作品最初的手稿。"}]}],"title":"原
  稿"}
      }, {
        "_index" : "moedict",
        "_type" : "revised",
        "_id" : "一面之緣",
        "_score" : 1.6941531, "_source" : {"heteronyms":[{"bopomofo":"ㄧ ㄇㄧㄢˋ ㄓ ㄩㄢ
13年4月20日星期六
用注音查

  # curl --silent -XPOST http://localhost:9200/moedict/revised/
  _search'?pretty' -d '{query:{text_phrase:{bopomofo:"ㄏㄨㄣˋ ㄏㄨ
  ㄣˋ"}}}' | grep _id

          "_id" : "   ",
          "_id" : "混混",
          "_id" : "混混沌沌",
          "_id" : "渾渾",




13年4月20日星期六
出現頻率最高的注音
    # curl --silent -XPOST http://localhost:9200/moedict/revised/_search'?pretty'
    -d '
    {
       "query" : {
          "match_all" : {}
       },
       "facets" : {
          "bpmf" : {
             "terms" : {
                "field" : "bopomofo"
             }
          }
       }
    }'




13年4月20日星期六
{
     "facets" : {
       "bpmf" : {
         "_type" : "terms",
         "missing" : 1485,
         "total" : 430736,
         "other" : 401706,
         "terms" : [ {
           "term" : "ㄅㄨˋ",
           "count" : 5400
         }, {
           "term" : "ㄕˋ",
           "count" : 4438
         }, {
           "term" : "ㄧˋ",
           "count" : 3218
         }, {
           "term" : "ㄧ",
           "count" : 2939
         }, {
           "term" : "ㄖㄣˊ",
           "count" : 2754
         }, {
           "term" : "ㄓ",
           "count" : 2625
         }, {
           "term" : "ㄌㄧˋ",
           "count" : 2580
         }, {
           "term" : "ㄗ",
           "count" : 2044
         }, {
           "term" : "ㄕˊ",
           "count" : 1541
         }, {
           "term" : "ㄒㄧㄣ",
           "count" : 1491
         } ]
       }
     }
13年4月20日星期六
FACETS



13年4月20日星期六
FACETS



        Aggregations

        SELECT SUM(salary) GROUP BY name FROM employee;




13年4月20日星期六
FACETS

        range

        term stats

        geo distance

        statistical

        date histogram



13年4月20日星期六
例:立院公報
      {
              "speaker" : "陳委員清寶",

          "content" : "我在推動小三通的時候,很多人都沒有注意到我真正的用意,除了
      是為當地爭取繁榮進步、增加建設的機會之外,我最著眼希望的是藉由小三通來催化全
      面的三通,能夠讓兩岸關係解凍。從 一個點切入,找一些議題與大陸進行對談。",

              "issue" : "3109"
      }


      {
              "speaker" : "李委員慶華",

              "content" : "希望包括核一、核二、核三、核四的安全係數都能提高。",

              "issue" : "3867"
      }

13年4月20日星期六
curl -XPOST http://localhost:9200/lyg0v/interp_body/_search'?pretty=1' -d '
    {
       "query": {
          "match_all": {}
       },
       "facets": {
          "top": {
            "terms": {
              "field": "content"
            }
          }
       }
    }'




13年4月20日星期六
curl -XPOST http://localhost:9200/lyg0v/interp_body/_search'?pretty=1' -d '
    {
       "query": {
          "match_all": {}
       },
       "facets": {
          "top": {
            "terms": {
              "field": "speaker"
            }
          }
       }
    }'




13年4月20日星期六
OPERATION



13年4月20日星期六
CLUSTERING


        auto-discovery

        auto-elected master

        data replication / partition

              with flexible shard / replica setting




13年4月20日星期六
13年4月20日星期六
13年4月20日星期六
shard ~ partition

              replica ~ duplication




13年4月20日星期六
CLUSTERING


        more shard

              faster indexing / scaling

        more replica

              faster searching / failover




13年4月20日星期六
13年4月20日星期六
STATS API

        http://www.elasticsearch.org/guide/reference/api/admin-
        cluster-nodes-stats/

        取得各項數據


        文件數、搜尋次數、累計搜尋時數、累計建索引時間

              cluster / primary / node / index 各種級別

         JVM CPU/Heap / OS / Thread / transport 使用狀態


13年4月20日星期六
JVM GC 圖




13年4月20日星期六
SEE ALSO


        Cool, Bonsai Cool - An introduction to ElasticSearch
        http://bit.ly/112xtsk

        The Road to a Distributed Search Engine
        http://bit.ly/ZqBBUt

        elasticsearch, Big Data, Search & Analytics
        http://bit.ly/11tmbyK




13年4月20日星期六
__END__
               OKTHXBYE
13年4月20日星期六

More Related Content

More from Kang-min Liu (19)

PDF
o̍h Tai-gi
Kang-min Liu
 
PDF
The architecture of search engines in Booking.com
Kang-min Liu
 
KEY
Perlbrew
Kang-min Liu
 
PDF
Same but Different
Kang-min Liu
 
PDF
perlbrew yapcasia 2010
Kang-min Liu
 
PDF
Git
Kang-min Liu
 
KEY
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
KEY
Learning From Ruby (Yapc Asia)
Kang-min Liu
 
KEY
YAPC::Tiny Introduction
Kang-min Liu
 
PDF
Integration Test With Cucumber And Webrat
Kang-min Liu
 
PDF
Good Evils In Perl
Kang-min Liu
 
PDF
Javascript Tutorial
Kang-min Liu
 
PDF
Javascript Basic
Kang-min Liu
 
PDF
Handlino - RandomLife
Kang-min Liu
 
PDF
Jformino
Kang-min Liu
 
PDF
Test Continuous
Kang-min Liu
 
PDF
網頁程式還可以怎麼設計
Kang-min Liu
 
PDF
OSDC.tw 2008 Lightening Talk
Kang-min Liu
 
PDF
Happy Designer 20080329
Kang-min Liu
 
o̍h Tai-gi
Kang-min Liu
 
The architecture of search engines in Booking.com
Kang-min Liu
 
Perlbrew
Kang-min Liu
 
Same but Different
Kang-min Liu
 
perlbrew yapcasia 2010
Kang-min Liu
 
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Learning From Ruby (Yapc Asia)
Kang-min Liu
 
YAPC::Tiny Introduction
Kang-min Liu
 
Integration Test With Cucumber And Webrat
Kang-min Liu
 
Good Evils In Perl
Kang-min Liu
 
Javascript Tutorial
Kang-min Liu
 
Javascript Basic
Kang-min Liu
 
Handlino - RandomLife
Kang-min Liu
 
Jformino
Kang-min Liu
 
Test Continuous
Kang-min Liu
 
網頁程式還可以怎麼設計
Kang-min Liu
 
OSDC.tw 2008 Lightening Talk
Kang-min Liu
 
Happy Designer 20080329
Kang-min Liu
 

Elasticsearch 實戰介紹

  • 1. ELASTICSEARCH 實戰介紹 Kang-min Liu <[email protected]> 13年4月20日星期六
  • 2. ELASTICSEARCH Distributed (Near) Real Time Search Engine RESTful 風,Lucene 骨,NoSQL 系 elasticsearch.org https://github.com/elasticsearch/elasticsearch elasticsearch.com 13年4月20日星期六
  • 3. 名詞對照 Relational DB ElasticSearch database index table type row document column field schema mapping index (全部) SQL query DSL 13年4月20日星期六
  • 4. CREATE curl -XPOST http://localhost:9200/social/tweet/1 -d '{ content: "大家好" user_name: "gugod" }' 13年4月20日星期六
  • 5. CREATE curl -XPOST http://localhost:9200/social/tweet/1 -d '{ content: "大家好" user_name: "gugod" }' 13年4月20日星期六
  • 6. CREATE curl -XPOST http://localhost:9200/social/tweet/1 -d '{ content: "大家好" user: { name: "gugod", id: 385782393, }, tag: ["osdctw", "demo", "moedict"] }' 13年4月20日星期六
  • 7. CREATE type curl -XPOST http://localhost:9200/social/tweet/1 -d '{ content: "大家好" index user_name: "gugod" }' 13年4月20日星期六
  • 8. READ curl -XGET http://localhost:9200/social/tweet/1 13年4月20日星期六
  • 9. UPDATE curl -XPUT http://localhost:9200/social/tweet/1 -d '{ content: "大家好" user_name: "gugod" }' 13年4月20日星期六
  • 10. DELETE curl -XDELETE http://localhost:9200/social/tweet/1 13年4月20日星期六
  • 11. SEARCH $ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{ "query": { "filtered" : { "query" : { "query_string" : { "query" : "some query string here" } }, "filter" : { "term" : { "user" : "kimchy" } } } } } query DSL ' 13年4月20日星期六
  • 12. SEARCH $ curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{ "query": { "term" : { "user" : "kimchy" } } } ' 13年4月20日星期六
  • 13. SEARCH $ curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=nihao' 13年4月20日星期六
  • 15. Inverted index 反向索引 term → id Relevance Scoring 分數 13年4月20日星期六
  • 16. 輸入文件 延展性: 物質具延長及展開的性質,稱為「延展性」。為大多數金屬之特性。 延平郡王: 明 成功的封號。 延年益壽: 延長壽命,多為頌祝人長壽的用詞。 延性: 物質可延長為細絲的性質,稱為「延性」。材料在破壞之前,呈現塑性變形的程 度。延性可用拉力試驗中的伸長率及斷面縮率表示之。 延緩: 延遲、延後。 13年4月20日星期六
  • 17. TOKENIZATION 延 展 性 物 質 具 延 長 及 展 開 的 性 質 稱 為 延 展 性 為 大 多 數 金 屬 之 特 性 延 平 郡 王 明 成 功 的 封 號 延 年 益 壽 延 長 壽 命 多 為 頌 祝 人 長 壽 的 用 詞 延 性 物 質 可 延 長 為 細 絲 的 性 質 稱 為 延 性 材 料 在 破 壞 之 前 呈 現 塑 性 變 形 的 程 度 延 性 可 用 拉 力 試 驗 中 的 伸 長 率 及 斷 面 縮 率 表 示 之 延 緩 延 遲 延 後 13年4月20日星期六
  • 18. TOKENIZATION 延展性: 物質 質具 具延 延長 長及 及展 展開 開的 的性 性質 稱為 延展 展性 為大 大多 多數 數金 金屬 屬之 之特 特性 延平郡王: 明 成 成功 功的 的封 封號 延年益壽: 延長 長壽 壽命 多為 為頌 頌祝 祝人 人長 長壽 壽的 的用 用詞 延性: 物質 質可 可延 延長 長為 為細 細絲 絲的 的性 性質 稱為 延性 材料 料在 在 破 破壞 壞之 之前 呈現 現塑 塑性 性變 變形 形的 的程 程度 延性 性可 可用 用拉 拉力 力試 試驗 驗中 中的 的伸 伸長 長率 率及 及斷 斷面 面縮 縮率 率表 表示 示之 延緩: 延遲 延後 13年4月20日星期六
  • 19. 搜尋:延長 延展性: 物質 質具 具延 延長 長及 及展 展開 開的 的性 性質 稱為 延展 展性 為大 大多 多數 數金 金屬 屬之 之特 特性 延平郡王: 明 成 成功 功的 的封 封號 延年益壽: 延長 長壽 壽命 多為 為頌 頌祝 祝人 人長 長壽 壽的 的用 用詞 延性: 物質 質可 可延 延長 長為 為細 細絲 絲的 的性 性質 稱為 延性 材料 料在 在 破 破壞 壞之 之前 呈現 現塑 塑性 性變 變形 形的 的程 程度 延性 性可 可用 用拉 拉力 力試 試驗 驗中 中的 的伸 伸長 長率 率及 及斷 斷面 面縮 縮率 率表 表示 示之 延緩: 延遲 延後 13年4月20日星期六
  • 20. 給分 延展性: 物質 質具 具延 延長 長及 及展 展開 開的 的性 性質 稱為 延展 展性 為大 大多 多數 0.5 金屬 屬之 之特 特性 數金 延平郡王: 明 成 成功 功的 的封 封號 0.7 延年益壽: 延長 長壽 壽命 多為 為頌 頌祝 祝人 人長 長壽 壽的 的用 用詞 延性: 物質 質可 可延 延長 長為 為細 細絲 絲的 的性 性質 稱為 延性 材料 料在 在 0.3 破 破壞 壞之 之前 呈現 現塑 塑性 性變 變形 形的 的程 程度 延性 性可 可用 用拉 拉力 力試 試驗 驗中 中的 的伸 伸長 長率 率及 及斷 斷面 面縮 縮率 率表 表示 示之 延緩: 延遲 延後 13年4月20日星期六
  • 21. 給分 文件的詞數(長度) 詞在文件內的頻率 詞在索引內的頻率 任意指定 13年4月20日星期六
  • 22. 給分 文件的詞數(長度) 詞在文件內的頻率 詞在索引內的頻率 任意指定 13年4月20日星期六
  • 23. 給分 文件的詞數(長度) 詞在文件內的頻率 詞在索引內的頻率 任意指定 13年4月20日星期六
  • 24. 給分 文件的詞數(長度) 詞在文件內的頻率 詞在索引內的頻率 任意指定 13年4月20日星期六
  • 26. TERM { "query": { "term": { "user": "ingy" } } } 13年4月20日星期六
  • 27. TEXT { "query": { "text": { "content": " 樣那樣" } } } 13年4月20日星期六
  • 28. TEXT { "query": { "text": { "content": " 樣那樣" } } 樣 樣那 那樣 } 13年4月20日星期六
  • 29. RANGE { "query": { "range" : { "age" : { "from" : 10, "to" : 20, "include_lower" : true, "include_upper": false, "boost" : 2.0 } } } } 13年4月20日星期六
  • 30. QUERY_STRING { "query": { "query_string" : { "query" : " 樣 AND 那樣 OR 怎樣" } } } 13年4月20日星期六
  • 31. WILDCARD { "query": { "wildcard" : { "user" : "ki*y" } } } 13年4月20日星期六
  • 32. MLT(MORE LIKE THIS) { "query": { "more_like_this" : { "like_text" : " 樣那樣", "min_term_freq" : 1, "max_query_terms" : 12 } } } 13年4月20日星期六
  • 33. 萌典 + ES https://github.com/g0v/esmoe 13年4月20日星期六
  • 34. 文件結構 { "heteronyms": [ { "bopomofo": "ㄧㄢˊ ㄓㄢˇ ㄒㄧㄥˋ", "bopomofo2": "yán jǎn shìng", "definitions": [ { "def": "物質具延長及展開的性質,稱為「延展性」。為大多 數金屬之特性。" } ], "pinyin": "yán zhǎn xìng" } ], "title": "延展性" }, 13年4月20日星期六
  • 35. 正查 # curl http://localhost:9200/moedict/revised/$(uri_escape 搜)'?pretty=1' { "_index" : "moedict", "_type" : "revised", "_id" : "搜", "_version" : 1, "exists" : true, "_source" : {"non_radical_stroke_count":10,"stroke_count": 13,"heteronyms":[{"bopomofo":"ㄙㄡ","pinyin":"sōu","bopomofo2":"sōu","definitions": [{"quote":["漢書.卷六.武帝紀:「秋,閉城門大搜,發謫戌屯五原。」","聊齋志異.卷一.狐 嫁女:「已而主人斂酒具,少一爵,冥搜不得。」"],"def":"找尋、尋求。","type":"動"}, {"example":["如:「搜身」。"],"quote":["元.王實甫.西廂記.第三本.第二折:「不肯搜自 己狂為,只待要覓別人破綻。」"],"def":"檢查、檢 點。","type":"動"}]}],"title":"搜","radical":"手"} } 13年4月20日星期六
  • 36. 反查(由義查詞) # curl --silent http://localhost:9200/moedict/revised/_search '?fields=&pretty=1&q='$(uri_escape 找尋) | grep _id "_id" : "尋根", "_id" : "尋找", "_id" : "訪求", "_id" : "探礦", "_id" : "尋求", "_id" : "找尋", "_id" : "找機會", "_id" : "自找", "_id" : "尋樂", "_id" : "探索", 13年4月20日星期六
  • 37. 用例句查 # curl --silent -XPOST http://localhost:9200/moedict/revised/_search'?pretty’ -d '{query:{text:{example: "紅樓夢" }}}' { "took" : 8, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 485, "max_score" : 5.116848, "hits" : [ { "_index" : "moedict", "_type" : "revised", "_id" : "抄本", "_score" : 5.116848, "_source" : {"heteronyms":[{"bopomofo":"ㄔㄠ ㄅㄣ ˇ","pinyin":"chāo běn","bopomofo2":"chāu běn","definitions":[{"link":["亦稱為「寫本」、「鈔 本」。"],"example":["如:「抄本紅樓夢」。"],"synonyms":"手本","def":"手抄的書 籍。"}]}],"title":"抄本"} }, { "_index" : "moedict", "_type" : "revised", "_id" : "一名", "_score" : 4.27241, "_source" : {"heteronyms":[{"bopomofo":"ㄧ ㄇㄧㄥˊ","pinyin":"yī míng","bopomofo2":"yī míng","definitions":[{"quote":["紅樓夢.第四十八回:「派下薛蟠之乳父 13年4月20日星期六
  • 38. 用引言查 # curl --silent -XPOST http://localhost:9200/moedict/revised/_search'?pretty' -d '{query:{text:{quote: "紅樓夢"}}}' { "took" : 18, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 11858, "max_score" : 1.7719736, "hits" : [ { "_index" : "moedict", "_type" : "revised", "_id" : "原稿", "_score" : 1.7719736, "_source" : {"heteronyms":[{"bopomofo":"ㄩㄢˊ ㄍㄠˇ","pinyin":"yuán gǎo","bopomofo2":"yuán gǎu","definitions":[{"synonyms":"底稿,稿本,初稿,草稿","quote":["紅樓夢.第五 回:「說畢,回頭命小鬟取了『紅樓夢』原稿來,遞與寶玉。」"],"def":"作品最初的手稿。"}]}],"title":"原 稿"} }, { "_index" : "moedict", "_type" : "revised", "_id" : "一面之緣", "_score" : 1.6941531, "_source" : {"heteronyms":[{"bopomofo":"ㄧ ㄇㄧㄢˋ ㄓ ㄩㄢ 13年4月20日星期六
  • 39. 用注音查 # curl --silent -XPOST http://localhost:9200/moedict/revised/ _search'?pretty' -d '{query:{text_phrase:{bopomofo:"ㄏㄨㄣˋ ㄏㄨ ㄣˋ"}}}' | grep _id "_id" : " ", "_id" : "混混", "_id" : "混混沌沌", "_id" : "渾渾", 13年4月20日星期六
  • 40. 出現頻率最高的注音 # curl --silent -XPOST http://localhost:9200/moedict/revised/_search'?pretty' -d ' { "query" : { "match_all" : {} }, "facets" : { "bpmf" : { "terms" : { "field" : "bopomofo" } } } }' 13年4月20日星期六
  • 41. { "facets" : { "bpmf" : { "_type" : "terms", "missing" : 1485, "total" : 430736, "other" : 401706, "terms" : [ { "term" : "ㄅㄨˋ", "count" : 5400 }, { "term" : "ㄕˋ", "count" : 4438 }, { "term" : "ㄧˋ", "count" : 3218 }, { "term" : "ㄧ", "count" : 2939 }, { "term" : "ㄖㄣˊ", "count" : 2754 }, { "term" : "ㄓ", "count" : 2625 }, { "term" : "ㄌㄧˋ", "count" : 2580 }, { "term" : "ㄗ", "count" : 2044 }, { "term" : "ㄕˊ", "count" : 1541 }, { "term" : "ㄒㄧㄣ", "count" : 1491 } ] } } 13年4月20日星期六
  • 43. FACETS Aggregations SELECT SUM(salary) GROUP BY name FROM employee; 13年4月20日星期六
  • 44. FACETS range term stats geo distance statistical date histogram 13年4月20日星期六
  • 45. 例:立院公報 { "speaker" : "陳委員清寶", "content" : "我在推動小三通的時候,很多人都沒有注意到我真正的用意,除了 是為當地爭取繁榮進步、增加建設的機會之外,我最著眼希望的是藉由小三通來催化全 面的三通,能夠讓兩岸關係解凍。從 一個點切入,找一些議題與大陸進行對談。", "issue" : "3109" } { "speaker" : "李委員慶華", "content" : "希望包括核一、核二、核三、核四的安全係數都能提高。", "issue" : "3867" } 13年4月20日星期六
  • 46. curl -XPOST http://localhost:9200/lyg0v/interp_body/_search'?pretty=1' -d ' { "query": { "match_all": {} }, "facets": { "top": { "terms": { "field": "content" } } } }' 13年4月20日星期六
  • 47. curl -XPOST http://localhost:9200/lyg0v/interp_body/_search'?pretty=1' -d ' { "query": { "match_all": {} }, "facets": { "top": { "terms": { "field": "speaker" } } } }' 13年4月20日星期六
  • 49. CLUSTERING auto-discovery auto-elected master data replication / partition with flexible shard / replica setting 13年4月20日星期六
  • 52. shard ~ partition replica ~ duplication 13年4月20日星期六
  • 53. CLUSTERING more shard faster indexing / scaling more replica faster searching / failover 13年4月20日星期六
  • 55. STATS API http://www.elasticsearch.org/guide/reference/api/admin- cluster-nodes-stats/ 取得各項數據 文件數、搜尋次數、累計搜尋時數、累計建索引時間 cluster / primary / node / index 各種級別 JVM CPU/Heap / OS / Thread / transport 使用狀態 13年4月20日星期六
  • 57. SEE ALSO Cool, Bonsai Cool - An introduction to ElasticSearch http://bit.ly/112xtsk The Road to a Distributed Search Engine http://bit.ly/ZqBBUt elasticsearch, Big Data, Search & Analytics http://bit.ly/11tmbyK 13年4月20日星期六
  • 58. __END__ OKTHXBYE 13年4月20日星期六