删除elasticsearch索引脚本
只保留七天的索引
shell版
#!/bin/bash
#hexm@2016.10.
#只保留一周es日志 logName=(
-nginxaccesslog
-nginxerrorlog
-phperrorlog
)
#es配置文件
config=/usr/local/app/elasticsearch-2.3./config/elasticsearch.yml
#日期
time=`date -d "7 day ago" +-%Y.%m.%d`
ip=`grep "network.host" ${config} | awk '{print$2}'`
port=`grep "http.port" ${config} | awk '{print$2}'`
#es监听的ip和端口
ipPort=${ip}:${port}
#循环删除
for ((i=;i<${#logName[*]};i++))
do
name=${logName[$i]}${time}
curl -XDELETE "http://${ipPort}/${name}"
done
python版
#!/usr/bin/python
# -*- coding:utf-8 -*-
#hexm@2016.10.18
#只保留一周es日志
#
import commands
from datetime import datetime, timedelta config = "/usr/local/app/elasticsearch-2.3.4/config/elasticsearch.yml"
logName = ('51-nginxaccesslog', '51-nginxerrorlog', '51-phperrorlog')
ip = commands.getoutput(""" grep "network.host" %s | awk '{print$2}' """ % config)
port = commands.getoutput(""" grep "http.port" %s | awk '{print$2}' """ % config) tm = datetime.now() + timedelta(days=-7)
tm = tm.strftime("%Y.%m.%d") for name in logName:
url = "http://" + str(ip) + ":" + str(port) + "/" + name + "-" + tm
print url
每天凌晨三点执行
###删除es索引
* * * /bin/bash /root/bin/delete_es.sh &>/dev/null &
删除elasticsearch索引脚本的更多相关文章
- 定时删除elasticsearch索引
从去年搭建了日志系统后,就没有去管它了,最近发现大半年各种日志的index也蛮多的,就想着写个脚本定时清理一下,把一些太久的日志清理掉. 脚本思路:通过获取index的尾部时间与我们设定的过期时间进行 ...
- 自动删除 Elasticsearch 索引
#!/bin/bash # author: Wang XiaoQiang# crontab -e# 0 0 * * * /root/script/del_esindex.sh # auto delet ...
- Elasticsearch 索引、更新、删除文档
一.Elasticsearch 索引(新建)一个文档的命令: curl XPUT ' http://localhost:9200/test_es_order_index/test_es_order_t ...
- Elasticsearch索引的操作,利用kibana(如何创建/删除一个es的索引?)
我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分 ...
- Elasticsearch索引的操作,利用kibana 创建/删除一个es的索引及mapping映射
索引的创建及删除 1. 通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射. 利用Kibana提供的DevTools来执行命令,要创建一个索引 ...
- ES3:ElasticSearch 索引
ElasticSearch是文档型数据库,索引(Index)定义了文档的逻辑存储和字段类型,每个索引可以包含多个文档类型,文档类型是文档的集合,文档以索引定义的逻辑存储模型,比如,指定分片和副本的数量 ...
- Elasticsearch索引和文档操作
列出所有索引 现在来看看我们的索引 GET /_cat/indices?v 响应 health status index uuid pri rep docs.count docs.deleted st ...
- Elasticsearch 索引的全量/增量更新
Elasticsearch 索引的全量/增量更新 当你的es 索引数据从mysql 全量导入之后,如何根据其他客户端改变索引数据源带来的变动来更新 es 索引数据呢. 首先用 Python 全量生成 ...
- windows系统中 利用kibana创建elasticsearch索引等操作
elasticsearch之借用kibana平台创建索引 1.安装好kibana平台 确保kibana以及elasticsearch正常运行 2.打开kibana平台在Dev Tools 3.创建一个 ...
随机推荐
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- java基础语法要点<一>(基于1.8)
http://yishouce.com/java/run http://www.shucunwang.com/RunCode/java/ 数据类型 8种基本数据类型及对应的 类型封装器 byte, s ...
- mysql解决无法远程客户端连接
1. 改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 " ...
- 转JAVA2
1.List遍历时删除的几种方式比较 1.1.会报错的删除方式: (1)在Iterator遍历时使用list删除 Iterator<String> it = list.iterator() ...
- iOS的nil,Null,NSNull的使用
今天做项目时,在数组里面取值时,发现里面有NSNull的对象,然后用数组里面对应的对象赋值时出现各种问题,总是报错.后面经过研究和查资料,总算解决了这一问题. nil用来给对象赋值(Objective ...
- js日历表
$scope.getCurrentWeek = function (day) { var days = ["星期日", "星期一", "星期二&quo ...
- BZOJ 2080: [Poi2010]Railway 双栈排序
2080: [Poi2010]Railway Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 140 Solved: 35[Submit][Statu ...
- js-this的用法,来自阮一峰老师的文章
1. 随着函数使用场合的不同,this的值会发生变化.但是有一个总的原则,那就是this指的是,调用函数的那个对象. 或者说,this指向当前执行的函数的所有者. 2.情况一:纯粹的函数调用 这是函数 ...
- 关于使用struts2时子窗体页面跳转后在父窗体打开的问题以及Session过期后的页面跳转问题
问题1:传统的系统界面,iframe了三个页面,上,左,右,用户点击注销的按钮在上面得top.jsp里面,方法:<a href="../adminAction/admin_logout ...
- ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet
严重: Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: Fai ...