该版本对于上一个版本做了升级。兼容性更好了。

#!/bin/bash
#######################################################
# $Name: clean_index.sh
# $Version: v2.0
# $Function: delete es index
# $Author: dongjiaxiao
# $Create Date: 2019-12-31
# $Description: shell
######################################################
#脚本的日志文件路径
CLEAN_LOG="/home/djx/scripts/clean_index.log"
#es地址
SERVER_PORT=172.17.1.212:9200
#保留的时间,单位天
DELTIME=45
SECONDS=$(date -d "$(date +%F) -${DELTIME} days" +%s)
INDEXS=$(curl -s -u elastic:changeme "${SERVER_PORT}/_cat/indices?v"|awk '{print $3}')
echo "-------------------$(date +%F_%T)---------------" >>${CLEAN_LOG}
for del_index in ${INDEXS}
do
timeString=$( echo ${del_index} |awk -F"-" '{print $NF}'|egrep "[0-9]*\.[0-9]*\.[0-9]*")
if [ -n "$timeString" ]
then
indexDate=${timeString//./-}
indexSecond=$( date -d ${indexDate} +%s )
if [ $(( $SECONDS- $indexSecond )) -gt 0 ]
then
delResult=`curl -s -u elastic:changeme -XDELETE "${SERVER_PORT}/"${del_index}"?pretty" |sed -n '2p'`
echo "delete index:$del_index result:$delResult" >>${CLEAN_LOG}
fi
fi done

elasticsearch定时删除索引第二版的更多相关文章

  1. Elasticsearch之删除索引

    1. #删除指定索引    # curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-2018.08.09    {&qu ...

  2. 第六篇 elasticsearch express 删除索引数据

    express 框架删除elasticsearch索引数据 1.在elasticsearch.js文件下添加 function deleteDocument(id) { return elasticC ...

  3. 定时删除elasticsearch索引

    从去年搭建了日志系统后,就没有去管它了,最近发现大半年各种日志的index也蛮多的,就想着写个脚本定时清理一下,把一些太久的日志清理掉. 脚本思路:通过获取index的尾部时间与我们设定的过期时间进行 ...

  4. Elasticsearch日志之删除索引

    1.查询索引 [root@ecs-- elasticsearch]# curl -XGET http://localhost:9200/* {,,},},},,,},},},,,},},},,,},} ...

  5. ElasticSearch 定时批量删除N天前的数据

    描述: 之前我已经完成了使用ElasticSearch.kibana.filebeat.三个工具完成分布式集群收集 分布在各个ip地址上的微服务日志,这样就可以统一的在一个服务器上查看了所有的微服务产 ...

  6. SQL优化 MySQL版 - 索引分类、创建方式、删除索引、查看索引、SQL性能问题

    SQL优化 MySQL版  - 索引分类.创建方式.删除索引.查看索引.SQL性能问题 作者 Stanley 罗昊 [转载请注明出处和署名,谢谢!] 索引分类 单值索引 单的意思就是单列的值,比如说有 ...

  7. 【转】ElasticSearch之定时删除数据

    有的时候我们在使用ES时,由于资源有限或业务需求,我们只想保存最近一段时间的数据,所以有如下脚本可以定时删除数据 delete_es_by_day.sh #!/bin/sh # example: in ...

  8. ElasticSearch.net NEST批量创建修改删除索引完整示例

    本示例采用Elasticsearch+Nest 网上查了很多资料,发现用C#调用Elasticsearch搜索引擎的功能代码很分散,功能不完整,多半是非常简单的操作,没有成型的应用示例.比如新增或修改 ...

  9. elasticsearch删除索引报错【原】

    如果elasticsearch删除索引报错 curl -X DELETE 'http://10.73.26.66:9200/httpd-34-2017.08.15' {"error" ...

随机推荐

  1. 什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?

    https://mp.weixin.qq.com/s/Co1LxS2h_ILh9syOmshjZg 什么是CGI CGI全称是“公共网关接口”(Common Gateway Interface),HT ...

  2. linux 一些简单操作

    vim   ----三种模式 1.命令模式           2.输出模式       3.底线命令模式 w(e) 移动光标到下一个单词 b 移动到光标上一个单词 数字0 移动到本行开头 $ 移动光 ...

  3. 2018-11-19-win10-uwp-使用-Matrix3DProjection-进行-3d-投影

    title author date CreateTime categories win10 uwp 使用 Matrix3DProjection 进行 3d 投影 lindexi 2018-11-19 ...

  4. Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)

    传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...

  5. [转]C#操作Word的超详细总结

    本文中用C#来操作Word,包括: 创建Word: 插入文字,选择文字,编辑文字的字号.粗细.颜色.下划线等: 设置段落的首行缩进.行距: 设置页面页边距和纸张大小: 设置页眉.页码: 插入图片,设置 ...

  6. python模块之hashlib模块

    hashlib模块:提供摘要算法 格式: hashlib格式: obj = hashlib.算法(md5,sha....) obj.update(摘要内容:bytes类型) result = obj. ...

  7. 2018-8-10-win10-uwp-绘图--Line-控件使用

    title author date CreateTime categories win10 uwp 绘图 Line 控件使用 lindexi 2018-08-10 19:16:51 +0800 201 ...

  8. 2019-8-31-AutoHotKey-用打码的快捷键

    title author date CreateTime categories AutoHotKey 用打码的快捷键 lindexi 2019-08-31 16:55:58 +0800 2019-06 ...

  9. CSU 2005: Nearest Maintenance Point(Dijkstra + bitset)

    Description A county consists of n cities (labeled 1, 2, …, n) connected by some bidirectional roads ...

  10. 一图理解vue生命周期

    博客园上传图不太清晰,可以查看我的CSDN https://blog.csdn.net/jiaoshuaiai/article/details/90046736 感谢: https://segment ...