您好,登錄后才能下訂單哦!
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的使用很簡單, 但是想用好, 不出問題或者少出問題, 得有一整套流程:
創(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 }
}
}
}
'
查看template
curl -XGET localhost:9200/_template/template_1?pretty
如果templates創(chuàng)建出錯, 刪除template
curl -XDELETE localhost:9200/_template/template_1
$ curl -XPUT 'http://localhost:9200/template_test/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
查看集群的狀態(tài), 如果分片副本設(shè)置錯誤, 有可能集群變成yellow
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
curl -XGET 'http://localhost:9200/twitter/_settings,_mappings?pretty'
curl -XGET 'http://localhost:9200/template_test/tweet/1'
經(jīng)過后面這些驗證, 一般就能規(guī)避大多數(shù)問題了.
免責聲明:本站發(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)容。