Elasticsearch 索引模板 Index Template, 并通过模板创建索引
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'
3. 批量构造数据
curl -u"username:pwd" -X POST '127.0.0.1:9200/friend_add_log_202112/_bulk?pretty' -H 'Content-Type: application/json' -d ' {"create":{}} {"self_im_id":"wxid_d9u29", "target_im_id":"wxid_ldu2e", "create_time":"2021-12-07 17:12:08"} {"create":{}} {"self_im_id":"wxid_d9u29", "target_im_id":"wxid_djf7d", "create_time":"2021-12-07 23:10:23"} {"create":{}} {"self_im_id":"wxid_d9u29", "target_im_id":"wxid_ake23", "create_time":"2021-12-07 12:11:55"} {"create":{}} {"self_im_id":"wxid_hdf51", "target_im_id":"wxid_ldu2e", "create_time":"2021-12-07 19:15:12"} {"create":{}} {"self_im_id":"wxid_hdf51", "target_im_id":"wxid_djf7d", "create_time":"2021-12-07 09:16:16"} {"create":{}} {"self_im_id":"wxid_hdf51", "target_im_id":"wxid_d7fuv", "create_time":"2021-12-07 15:11:29"} {"create":{}} {"self_im_id":"wxid_rte11", "target_im_id":"wxid_d7fuv", "create_time":"2021-12-06 07:45:53"} {"create":{}} {"self_im_id":"wxid_rte11", "target_im_id":"wxid_d7fuv", "create_time":"2021-12-05 19:10:49"} {"create":{}} {"self_im_id":"wxid_rte11", "target_im_id":"wxid_d7fuv", "create_time":"2021-12-02 10:00:39"} {"create":{}} {"self_im_id":"wxid_hj2u2", "target_im_id":"wxid_fgq62", "create_time":"2021-12-07 21:01:53"} {"create":{}} {"self_im_id":"wxid_hj2u2", "target_im_id":"wxid_fgq62", "create_time":"2021-12-06 09:54:01"} '
点击链接加入群聊【互联网技术交流群】:282575808
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架