Elasticsearch 索引模板 Index Template, 並通過模板建立索引
阿新 • • 發佈:2021-12-09
ES version: 7.11
1. 索引模板
1.1 新建模板
Create or update index template API
curl -u"username:pwd" -XPUT '127.0.0.1:9200/_index_template/friend_add_log?pretty' -H'Content-Type: application/json' -d ' { "index_patterns": ["friend_add_log*"], "priority": 0, "template": { "settings": {"index": { "analysis": { "normalizer": { "my_lowercase": { "type": "custom", "filter": ["lowercase"] } } } },"number_of_shards": 3, "number_of_replicas": 0 }, "mappings": { "properties": { "self_im_id": { "type": "keyword" }, "target_im_id": { "type": "keyword" },"create_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||epoch_millis" } } }, "aliases": { "friend_add_log": {} } } } '
1.2 檢視模板是否存在
curl -u"username:pwd" -I '127.0.0.1:9200/_index_template/friend_add_log?pretty'
1.3 檢視索引模板
curl -u"username:pwd" -XGET '127.0.0.1:9200/_index_template/friend_add_log?pretty'
1.4 刪除模板
# 從 ES 7.8 開始提供的新版API, 與舊版共存; 刪除使用新版API建立的索引模板需要用新版API, 舊版與舊版對應. 兩種版本的API不可混用; curl -u"username:pwd" -X DELETE "127.0.0.1:9200/_index_template/friend_add_log?pretty" # 舊版API curl -u"username:pwd" -X DELETE "127.0.0.1:9200/_template/friend_add_log?pretty"
2. 建立索引
2.1 建立索引 friend_add_log_202112
curl -u"username:pwd" -XPUT '127.0.0.1:9200/friend_add_log_202112?pretty' -H 'Content-Type: application/json' -d '{}'
索引friend_add_log_202112 會命中模板friend_add_log, 因此會按照模板建立索引. 或者第一次 put 資料的時候, 如果索引不存在, 也會自動根據模板建立索引. 比如例子中的friend_add_log_202112, 就可以根據月份滾動建立索引.
2.1檢視索引資訊, 包括建立時間
curl -u"username:pwd" -XGET '127.0.0.1:9200/friend_add_log_202112?pretty'
點選連結加入群聊【網際網路技術交流群】:282575808