elasticsearch实现按天翻滚索引
最近在做集中式日志,将应用的日志保存到Elasticsearch中,结合kibana实现集中化日志监控和报警。在设计ES存储的时候。考虑到日志的特殊性,打算采用Daily Indices方式。名称为:log-${application}-YYYY.MM.DD。每天会自动创建一个新的索引,类似于log4j的DailyRollingFileAppender,一来减少活跃索引的大小,二来方便存档和删除。
但是这个不是ES内建的功能,需要应用自己实现,方法有很多种。结合ES提供的功能,最简单的方式是采用如下方式:
- indices templates 为 log-* 的index应用同样的settings、mappings和alias
- 启动 automatic index creation,而且支持黑白名单,这样就不需要每次先创建索引了
具体步骤如下:
A.配置 elasticsearch.yml,开启自动创建索引白名单,但是仍然关闭动态mapper:
action.auto_create_index: +log*,-*
index.mapper.dynamic: false
B.为log-*的索引添加如下index-templates:
PUT /_template/log_template
{
"template" : "log-*",
"mappings" : {
"loggingMessage": {
"properties": {
"postDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
},
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
},
"timestamp": {
"type": "long"
},
"env": {
"type": "string",
"index": "not_analyzed"
},
"type": {
"type": "string",
"index": "not_analyzed"
},
"host": {
"type": "string",
"index": "not_analyzed"
},
"application": {
"type": "string",
"index": "not_analyzed"
},
"threadName": {
"type": "string"
},
"locationInfo": {
"type": "string"
},
"level": {
"type": "string",
"index": "not_analyzed"
},
"message": {
"type": "string"
},
"stackTrace": {
"type": "string"
}
}
}
}
}
注:关闭auto_create_index和dindex.mapper.dynamic对Kibana的影响。根据ES的推荐,建议将auto_create_index和dindex.mapper.dynamic都关闭
action.auto_create_index: +log*,-*
index.mapper.dynamic: false
但是Kibana的Dashboard Schema也是存储在ES索引中,而且是动态创建的。这就会导致Kibana的Dashboard无法保存。简单而粗暴的解决方案就是手动创建kibana的索引和mapping:
PUT /kibana-int/dashboard/_mapping
{
"dashboard": {
"properties": {
"title": {
"type": "string"
},
"user": {
"type": "string"
},
"dashboard": {
"type": "string"
},
"group": {
"type": "string"
}
}
}
}
参见:http://blog.arganzheng.me/posts/daily-indices-with-elasticsearch.html
elasticsearch实现按天翻滚索引的更多相关文章
- Elasticsearch-基础介绍及索引原理分析(转载)
最近在参与一个基于Elasticsearch作为底层数据框架提供大数据量(亿级)的实时统计查询的方案设计工作,花了些时间学习Elasticsearch的基础理论知识,整理了一下,希望能对Elastic ...
- Elasticsearch-基础介绍及索引原理分析
介绍 Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene(TM) 基础上的搜索引擎.当然 Elasticsearch 并不仅仅是 L ...
- elasticsearch简介和倒排序索引介绍
介绍 我们为什么要用搜索引擎?我们的所有数据在数据库里面都有,而且 Oracle.SQL Server 等数据库里也能提供查询检索或者聚类分析功能,直接通过数据库查询不就可以了吗?确实,我们大部分的查 ...
- 高效管理 Elasticsearch 中基于时间的索引——本质是在利用滚动模式做数据的冷热分离,热索引可以用ssd
高效管理 Elasticsearch 中基于时间的索引 转自:http://stormluke.me/es-managing-time-based-indices-efficiently/ 用 Ela ...
- Docker安装ElasticSearch 以及使用LogStash实现索引库和数据库同步
1:下载 ElasticSearch 镜像 docker pull docker.io/elasticsearch:5.6.8 2:创建 ElasticSearch 容器: 注意:5.0默认分配jvm ...
- ElasticSearch(六):索引模板
ElasticSearch(六):索引模板 学习课程链接<Elasticsearch核心技术与实战> Index Template Index Template - 帮助你设定Mappin ...
- elasticsearch自动按天创建索引脚本
elasticsearch保存在一个索引中数据量太大无法查询,现在需要将索引按照天来建,查询的时候关联查询即可 有时候es集群创建了很多索引,删不掉,如果是测试环境或者初始化es集群(清空所有数据), ...
- ElasticSearch权威指南学习(索引管理)
创建索引 当我们需要确保索引被创建在适当数量的分片上,在索引数据之前设置好分析器和类型映射. 手动创建索引,在请求中加入所有设置和类型映射,如下所示: PUT /my_index { "se ...
- elasticsearch 导入基础数据并索引之 geo_point
elasticsearch 中的地理信息存储, 有geo_point形式和geo_shape两种形式 此篇只叙述geo_point, 地理位置需要声明为特殊的类型, 不显示在mapping中定义的话, ...
随机推荐
- 文档的js
/* 主站,子频道,定向站点共用 */ (function() { scrollToAnchor(); toggleSearchForm(); scrollTop(); initScrollBar() ...
- [Algorithm] Reservoir Sampling
Given a stream of elements too large to store in memory, pick a random element from the stream with ...
- Mathematica 文本界面获得之前的结果
使用%号做标记.获得文本界面之前的运算结果:
- UML关系(泛化,实现,依赖,关联(聚合,组合))
http://www.cnblogs.com/olvo/archive/2012/05/03/2481014.html UML类图关系(泛化 .继承.实现.依赖.关联.聚合.组合) 继承.实现.依赖. ...
- LintCode: Triangle
C++ 逆推 class Solution { public: /** * @param triangle: a list of lists of integers. * @return: An in ...
- bash if 表达式含义
[ -a FILE ] 如果 FILE 存在则为真. [ -b FILE ] 如果 FILE 存在且是一个块特殊文件则为真. [ -c FILE ] 如果 FILE 存在且是一个字特殊文件则为真. [ ...
- 微软BI 之SSRS 系列 - 报表中分组聚合中处理不规则层次结构的技巧(没有子元素的时候不展开, 删除+符号)
分组聚合的展开和收起效果在SSRS Report中非常常用,并且有时还要处理一些比较特别的情况.比如分组合并时有的层次结构是不规则的,有的组有两层,遇到这种情况应该如何处理? 注意到下面的这个需求 ...
- eclipse 使用总结
1.eclipse 运行简单JAVA程序事例 2.eclipse 安装lombok 3.eclipse 远程调试程序 4.eclipse 经常弹出提示框 5.eclipse 修改设置Ctrl+Shif ...
- NameNode重新格式化以后DataNode不能启动
最近重新格式化NameNode以后,发现几个DataNode都不能启动了. 这是因为dfs.name.dir路径下面有一个current/VERSION文件,里面有一个clusterID,重新格式化以 ...
- Atlas系列一:【已解决】error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory
1:Atlas的安装 https://github.com/Qihoo360/Atlas/wiki/Atlas的安装 2: [root@localhost bin]# ./mysql-proxyd t ...