定时删除elasticsearch索引】的更多相关文章

从去年搭建了日志系统后,就没有去管它了,最近发现大半年各种日志的index也蛮多的,就想着写个脚本定时清理一下,把一些太久的日志清理掉. 脚本思路:通过获取index的尾部时间与我们设定的过期时间进行对比,如果是属于过期时间那么就进行删除,并写入日志.如果不是则不进行处理. 完整的脚本:(今天准备写个,翻下笔记发现去年就已经写好了) #!/bin/bash ###################################################### # $Name: clean_…
只保留七天的索引 shell版 #!/bin/bash #hexm@ #只保留一周es日志 logName=( -nginxaccesslog -nginxerrorlog -phperrorlog ) #es配置文件 config=/usr/local/app/elasticsearch-/config/elasticsearch.yml #日期 time=`date -d "7 day ago" +-%Y.%m.%d` ip=`grep "network.host&quo…
脚本如下 一.python 脚本如下 #! /usr/bin/python # -*- coding=utf-8 -*- import urllib import urllib.request import re import datetime import time import codecs from urllib.request import urlopen import requests def match(urlGet): urlGet1 = urllib.request.urlope…
#!/bin/bashfind /data/elasticsearch/data/kz-log/nodes/0/indices/ -type d -mtime +5 |  awk -F"/" '{print $9}' | grep -v kibana | uniq >esindex.txtcat /home/wwwad/.sh/esindex.txt | while read linedoecho ${line}curl -XDELETE "http://10.19.1…
#!/bin/bash # author: Wang XiaoQiang# crontab -e# 0 0 * * * /root/script/del_esindex.sh # auto delete day ago elasticsearch index dtime=`date -d "7 day ago" +%Y-%m-%d` dtime_stamp=`date -d "$dtime" +%s` indexs=`curl -s 'http://127.0.0.…
有的时候我们在使用ES时,由于资源有限或业务需求,我们只想保存最近一段时间的数据,所以有如下脚本可以定时删除数据 delete_es_by_day.sh #!/bin/sh # example: index_name=$ daycolumn=$ savedays=$ format_day=$ if [ ! -n "$savedays" ]; then echo "the args is not right,please input again...." exit f…
一.Elasticsearch 索引(新建)一个文档的命令: curl XPUT ' http://localhost:9200/test_es_order_index/test_es_order_type/1 ' -d ' { "id": 5, "name": "test555", "skuName": "55", "age":23 } ' 这里test_es_order_index…
curl -u 用户名:密码 -H'Content-Type:application/json' -d'{ "query": { "range": { "@timestamp": { "lt": "now-7d", "format": "epoch_millis" } } } } ' -XPOST "http://127.0.0.1:9200/*-*/_de…
我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分片,并且在我们索引任何数据 之前 ,分析器和映射已经被建立好.费话不多说,我们来看. 利用Kibana提供的DevTools来执行命令,要创建一个索引 put /sdb  (其中sdb为一个索引) 创建成功后会返回如下结果 { "acknowledged" : true, "sh…
一 简介:本文介绍创建自动删除数据的TTL索引 二 目的 定时删除数据三 创建方法   db.collection.createIndex(keys, options)   options:   expireAfterSeconds 指定多少秒或者包含日期值的数组 创建示例   db.eventlog.createIndex( { "lastModifiedDate": 1 }, { expireAfterSeconds: 3600 },{backgroup: true}) 四 何时失…