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中定义的话, ...
随机推荐
- 火星坐标、百度坐标、WGS84坐标转换代码(JS、python版)
火星坐标.百度坐标.WGS84坐标转换代码(JS.python版) 一.JS版本源码 github:https://github.com/wandergis/coordTransform /** * ...
- 曾经的超级明星类库jQuery未来也许不再会被前端程序猿追捧了!
作为火了十多年的老牌明星类库jQuery, 相信做前端的小伙伴肯定都或多或少的使用和追捧过,当然我也不例外, 作为第一个学习的js类库,我曾经也觉得它是真正的唯一, 帮助你处理恶心的浏览器CSS/JS ...
- “服务器推”技术【转载+整理】
原文地址 本文内容 "服务器推(server-push)"技术的应用 基于客户端套接口的"服务器推"技术 基于 HTTP 长连接的"服务器推" ...
- android中去掉ListView控件中的分割线
通过设置android:divider="@null" ,可以去掉ListView控件中的分割线 也可以自定义分割线的颜色,比如: <ListView android:id= ...
- iOS 画虚线
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )]; [self.view addSubvi ...
- 再玩 DevStack(Mitaka版)- 基于 trystack.cn 源
曾经就写过一篇关于DevStack安装OpenStack的文章< 使用 DevStack 高速部署 OpenStack 开发环境 >,时过境迁,如今有更好的方式来实现.想到曾经的复杂性,认 ...
- Valid Number 验证数字
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
- error: expected unqualified-id extern "C" {
通常为include该文件的头文件内类的声明处未加“:”
- java 生成二维码后叠加LOGO并转换成base64
1.代码 见文末推荐 2.测试 测试1:生成base64码 public static void main(String[] args) throws Exception { String dat ...
- 〖Android〗联想K860 logcat CM11.0出错信息及解决
错误1: D/gpsd ( ): main() D/gpsd ( ): argv[] = '/system/bin/glgps' D/gpsd ( ): argv[] = '-c' D/gpsd ( ...