溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ES學(xué)習(xí)筆記之---template的使用

發(fā)布時間:2020-04-11 07:27:59 來源:網(wǎng)絡(luò) 閱讀:34379 作者:sbp810050504 欄目:大數(shù)據(jù)

es提供template功能的出發(fā)點在哪里呢? 作為NoSQL數(shù)據(jù)庫, ES在數(shù)據(jù)入庫前是不做schema設(shè)定的, 也就是不限定數(shù)據(jù)字段.這對日志類型的數(shù)據(jù)來說, 是個利好的場景. 但是這種不設(shè)定schema的做法, 有時有太過自由. 有些業(yè)務(wù)場景, 我們需要預(yù)先設(shè)定field的分詞方式. 這時固然可以使用mappings解決. 但是業(yè)務(wù)接入前要通知一下,先建個索引, 想想有點不智能. 有沒有更靈活一點的做法呢? templates

templates的使用很簡單, 但是想用好, 不出問題或者少出問題, 得有一整套流程:

  1. 創(chuàng)建template

    curl -XPUT localhost:9200/_template/template_1 -d '
    {
    "template" : "te*",
    "settings" : {
        "number_of_shards" : 1,
        "number_of_replications":2
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : false }
        }
    }
    }
    '
  2. 查看template

    curl -XGET localhost:9200/_template/template_1?pretty
  3. 如果templates創(chuàng)建出錯, 刪除template

    curl -XDELETE localhost:9200/_template/template_1
  4. template建好后, 要測試一下是否符合預(yù)期, 添加一條數(shù)據(jù)
    $ curl -XPUT 'http://localhost:9200/template_test/tweet/1' -d '{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elasticsearch"
    }'
  5. 查看集群的狀態(tài), 如果分片副本設(shè)置錯誤, 有可能集群變成yellow

    curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
  6. 查看索引結(jié)構(gòu)及數(shù)據(jù)樣例
    curl -XGET 'http://localhost:9200/twitter/_settings,_mappings?pretty'
    curl -XGET 'http://localhost:9200/template_test/tweet/1'

經(jīng)過后面這些驗證, 一般就能規(guī)避大多數(shù)問題了.

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI