2018-08-16更新 修正支持5.X全系 最新6.X 版本自动清除索引 增加权限验证。
本人是C#开发者,写起Nodejs估计还保留着浓浓的C#风格吧。
elasticsearch简单说一下,索引一般推荐以日期为单位。没啥原因大家的经验而已。
elasticsearch相关资料:https://www.elastic.co/guide/en/elasticsearch/client/index.html
https://github.com/elastic/elasticsearch
indices.delete 删除索引
indices.get 获取索引信息
create 建立索引并插入信息,如存在则追加信息。
这里我们看的是2.4的,5.X的应该也没啥大问题。这些都是相对简单的。
配置文件AppConfig.js
clearhistory:
indexPrefix:索引前缀,分割符为下划线("_")。日期格式之间为"-"。索引格式为:xxx_xxx_2017-02-17
month:保留几个月
day:保留几天
apiVersion:'5.6' //es服务端对应的版本号 切记切记要对应否则获取索引及其它可能会报错
AppConfig.js源码
var AppConfig = {
debug: false,
elasticSearch: {
hosts: ['http://192.168.151.190:9200/'],//ES服务器IP地址
sniffOnStart: false,
sniffInterval: 300000,
httpAuth:'elastic:elastic2018',
keepAlive:true,
connectionClass:"http",
apiVersion:'5.6' //es服务端对应的版本号 切记切记要对应否则获取索引及其它可能会报错
},
clearhistory: [{
indexPrefix: 'xxx_xxx_',
month: 0,
day: 6
}, {
indexPrefix: 'xxx_frontend_',
month: 0,
day: 1
}, {
indexPrefix: 'xxx_',
month: 0,
day: 1
}],
log4js: {
appenders: [{
type: 'dateFile',
absolute: true,
filename: './logs/',
maxLogSize: 1024 * 1024,
backup: 3,
pattern: 'yyyy-MM-dd.txt',
alwaysIncludePattern: true,
category: 'normal'
}],
replaceConsole: false
}
};
module.exports = AppConfig;
ClearHistoryES.js
主要函数