白话Elasticsearch73_ES生产集群中的索引管理02
文章目录
- 概述
- 官方指导
- 1、mapping管理
- 2、索引别名管理
- 3、index settings管理
- 3.1 Update index settings API
- 3.2 Get index settings API
- 4、index template
- 4.0 官方文档
- 4.1 新建/更新模板
- 4.2 删除模板
- 4.3 查看模板
- 4.4 使用模板创建索引
- 4.5 模板的使用场景
概述
继续跟中华石杉老师学习ES,第74篇
课程地址: https://www.roncoo.com/view/55
官方指导
Index APIs: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html
1、mapping管理
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html#mapping-management
put mapping命令可以让我们给一个已有的索引添加一个新的type,或者修改一个type,比如给某个type加一些字段
put mapping: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
下面这个命令是在创建索引的时候,直接跟着创建一个type
curl -XPUT 'http://elasticsearch02:9200/twitter?pretty' -d '
{"mappings": {"tweet": {"properties": {"message": {"type": "text"}}}}
}'
下面这个命令是给一个已有的索引添加一个type 。 7.x 已经取消这个功能了,了解即可。
curl -XPUT 'http://elasticsearch02:9200/twitter/_mapping/user?pretty' -d '
{"properties": {"name": {"type": "text"}}
}'
下面这个命令是给一个已有的type添加一个field
curl -XPUT 'http://elasticsearch02:9200/twitter/_mapping/tweet?pretty' -d '
{"properties": {"user_name": {"type": "text"}}
}'
curl -XGET 'http://elasticsearch02:9200/twitter/_mapping/tweet?pretty'
,上面这行命令可以查看某个type的mapping映射信息
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
curl -XGET 'http://elasticsearch02:9200/twitter/_mapping/tweet/field/message?pretty'
,这行命令可以看某个type的某个field的映射信息
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html
Type exists API https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html
mapping管理是运维中,索引管理中,很基础的一块
2、索引别名管理
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html#alias-management
curl -XPOST 'http://elasticsearch02:9200/_aliases?pretty' -d '
{"actions" : [{ "add" : { "index" : "twitter", "alias" : "twitter_prod" } }]
}'
curl -XPOST 'http://elasticsearch02:9200/_aliases?pretty' -d '
{"actions" : [{ "remove" : { "index" : "twitter", "alias" : "twitter_prod" } }]
}'
POST /_aliases
{"actions" : [{ "remove" : { "index" : "test1", "alias" : "alias1" } },{ "add" : { "index" : "test2", "alias" : "alias1" } }]
}
POST /_aliases
{"actions" : [{ "add" : { "indices" : ["test1", "test2"], "alias" : "alias1" } }]
}
上面是给某个index添加和删除alias的命令,还有重命名alias的命令(先删除再添加),包括将一个alias绑定多个index
POST /_aliases
{"actions" : [{"add" : {"index" : "test1","alias" : "alias2","filter" : { "term" : { "user" : "kimchy" } }}}]
}
DELETE /logs_20162801/_alias/current_day
GET /_alias/2016
索引别名,还是挺有用的,主要是什么呢,就是说,可以将一个索引别名底层挂载多个索引,比如说7天的数据
索引别名常常和之前讲解的那个rollover结合起来,我们为了性能和管理方便,每天的数据都rollover出来一个索引,但是在对数据分析的时候,可能是这样子的,有一个索引access-log,指向了当日最新的数据,用来计算实时数据的; 有一个索引access-log-7days,指向了7天的7个索引,可以让我们进行一些周数据的统计和分析。
3、index settings管理
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html#index-settings
3.1 Update index settings API
语法
PUT /<index>/_settings
curl -XPUT 'http://elasticsearch02:9200/twitter/_settings?pretty' -d '
{"index" : {"number_of_replicas" : 1}
}'
3.2 Get index settings API
curl -XGET 'http://elasticsearch02:9200/twitter/_settings?pretty'
经常可能要对index做一些settings的调整,常常和之前的index open和close结合起来使用
4、index template
4.0 官方文档
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html#index-templates
我们可以定义一些index template,这样template会自动应用到根据匹配规则( based on an index pattern)匹配到的新创建的索引上去。
template中可以包含settings和mappings,还可以包含一个pattern,决定了template会被应用到哪些index上。
而且template仅仅在index创建的时候会被应用,修改template,是不会对已有的index产生影响的。
4.1 新建/更新模板
语法:
PUT /_template/<index-template>
创建或者更新模板
curl -XPUT 'http://elasticsearch02:9200/_template/template_access_log?pretty' -d '
{"template": "access-log-*","settings": {"number_of_shards": 2},"mappings": {"log": {"_source": {"enabled": false},"properties": {"host_name": {"type": "keyword"},"created_at": {"type": "date","format": "EEE MMM dd HH:mm:ss Z YYYY"}}}},"aliases" : {"access-log" : {}}
}'
4.2 删除模板
curl -XDELETE 'http://elasticsearch02:9200/_template/template_access_log?pretty'
# 删除模板
DELETE _template/template_1
返回
{"acknowledged": true
}
4.3 查看模板
curl -XGET 'http://elasticsearch02:9200/_template/template_access_log?pretty'
# 查看所有的模板
GET _template# 查看特定的模板
GET _template/template_1
4.4 使用模板创建索引
curl -XPUT 'http://elasticsearch02:9200/access-log-01?pretty'
查看索引, 观察模板是否被自动的关联到了匹配的模板上了。
curl -XGET 'http://elasticsearch02:9200/access-log-01?pretty'
# 新建索引 匹配模板的index_patterns
PUT test
GET test/_mapping
4.5 模板的使用场景
index template使用场景: 举个例子你可能会经常创建不同的索引,比如说商品,分成了多种,每个商品种类的数据都很大,可能就是说,一个商品种类一个索引,但是每个商品索引的设置是差不多的,所以干脆可以搞一个商品索引模板,然后每次新建一个商品种类索引,直接绑定到模板,引用相关的设置。
简言之,将公共的东西抽取到模板中,省去了一遍一遍设置的麻烦。
白话Elasticsearch73_ES生产集群中的索引管理02相关推荐
- 白话Elasticsearch73_ES生产集群中的索引管理01
文章目录 概述 官方指导 1.创建索引 (1)创建索引的语法 (2)索引创建返回消息的解释 2.删除索引 3.查询索引设置信息 4. Index 是否存在 5.打开/关闭索引 5.压缩索引 6.rol ...
- 白话Elasticsearch70-ES生产集群部署之production mode下启动时的bootstrap check
文章目录 概述 官方文档 什么是bootstrap check(启动时检查)? development mode vs. production mode heap size check file de ...
- 白话Elasticsearch69-ES生产集群部署重要的 Elasticsearch参数设置
文章目录 ES的重要参数设置 官方文档 Path settings Cluster name Node name Network host Discovery settings Heap size H ...
- 【Elasticsearch】我们如何在 5 天内在同一个 Elasticsearch 集群中重新索引 360 亿份文档
1.概述 翻译:https://thoughts.t37.net/how-we-reindexed-36-billions-documents-in-5-days-within-the-same-el ...
- 白话Elasticsearch71-ES生产集群部署之各个节点以daemon模式运行以及优雅关闭
文章目录 概述 官方指导 启动 ES 优雅的关闭 ES 概述 继续跟中华石杉老师学习ES,第71篇 课程地址: https://www.roncoo.com/view/55 官方指导 启动ES htt ...
- 白话Elasticsearch68-ES生产集群部署重要的操作系统设置
文章目录 概述 系统的重要配置 开发模式 vs 生产模式 (Bootstrap Checks) 配置系统设置 files descriptors 临时设置 永久设置 设置jvm option 禁止sw ...
- 白话Elasticsearch72_利用HDFS备份与恢复ES生产集群的数据
文章目录 概述 官方指导 hadoop hdfs分布式文件存储系统介绍 hdfs环境搭建 基于snapshot+hdfs进行数据备份 0.es集群数据备份的必要性 1.ES数据备份储存如何选择? 2. ...
- 白话Elasticsearch64-zen discovery集群发现机制
文章目录 概述 zen discovery集群发现机制 (1)ping (2)unicast (3)master选举 (4)集群故障的探查 (5)集群状态更新 (6)不因为master宕机阻塞集群操作 ...
- 白话Elasticsearch63-生产集群部署之硬件配置、jvm以及集群规划建议
文章目录 概述 内存 CPU 磁盘 网络 自建集群 vs 云部署 JVM 容量规划 概述 继续跟中华石杉老师学习ES,第63篇 课程地址: https://www.roncoo.com/view/55 ...
最新文章
- 新视野教育计算机题库,校园网.新视野教育计算机等级考试《二级公共基础》课后习题答案...
- hashmap 遍历_别慌,送你21 个面试官必问HashMap考点
- HashMap 为什么在链表长度为 8 的时候转红黑树,为啥不能是 9 是 10?
- 如何在JavaScript中将浮点数转换为整数?
- Angr安装与使用之使用篇(十)
- Docker从理论到实践(二)------配置Docker镜像源加速器(部分使用效果已不太理想)
- 获取电脑的唯一识别码_无锡电脑办公,office软件培训,学会为止
- springboot+华迪企业合同管理平台 毕业设计-附源码191555
- Splunk:大数据智能分析平台全能日志分析利器
- c++快速傅里叶变换、反变换(FFT、IFFT)
- 认知升级:什么才是真正的高情商?
- JavaSE基础知识
- special effects - 星空宇宙背景特效
- SpringSecurity:密码登录与token登录过程理解
- 大数据技术解决 征信环节中产生的问题
- 爬了深圳3W+二手房我发现了这些秘密
- 《Real-Time Rendering 4th Edition》读书笔记--简单粗糙翻译 第二章 渲染管线 The Graphics Rendering Pipeline
- 冒泡排序Matlab程序超详细注释
- SAP 详细解析在建工程转固定资产
- 梦幻联动-MogDB与ShardingSphere在TPC-C上的表现
热门文章
- python魔法方法好难_一篇干货好文,轻松掌握python魔法方法
- linux java平台,如何下载和安装用于 Linux 平台的 Java
- python 切割字符串
- arduino定时器控制舵机_Arduino学习经验(一)之解决舵机库和pwm输出冲突
- 点云网络的论文理解(二)- PointNet的pytorch复现
- python 笔记:nltk (标记英文单词词性等)
- 错误处理:one of the variables needed for gradient computation has been modified by inplace operation
- Linux中的通配符
- Python入门100题 | 第027题
- 【LeetCode从零单排】No70.ClimbingStairs