码迷,mamicode.com
首页 > 其他好文 > 详细

删除elasticsearch大于7天前的索引

时间:2019-05-28 12:38:40      阅读:486      评论:0      收藏:0      [点我收藏+]

标签:type   json   format   大于   pos   search   arc   pre   http   

curl -u 用户名:密码  -H‘Content-Type:application/json‘ -d‘{
    "query": {
        "range": {
            "@timestamp": {
                "lt": "now-7d",
                "format": "epoch_millis"
            }
        }
    }
}
‘ -XPOST "http://127.0.0.1:9200/*-*/_delete_by_query?pretty"

技术图片

{
    "query": {
        "range": { //范围
            "@timestamp": {//时间字段
                "lt": "now-7d",//lt是小于(<),lte是小于等于(<=),gt是大于(>),gte是大于等于(>=),now-7d是当前时间减7天
                "format": "epoch_millis"
            }
        }
    }
}  

定时删除

$ crontab -e

* 0 * * * /usr/bin/curl -u username:password  -H‘Content-Type:application/json‘ -d‘{"query":{"range":{"@timestamp":{"lt":"now-7d","format":"epoch_millis"}}}}‘ -XPOST "http://127.0.0.1:9200/*-*/_delete_by_query?pretty" 

k8s cronJob

apiVersion: batch/v1beta1
kind: CronJob
metadata:
 name: elasticsearch
 namespace: elasticsearch
 labels:
   app.kubernetes.io/name: elasticsearch
spec:
  successfulJobsHistoryLimit: 10 
  failedJobsHistoryLimit: 10
  concurrencyPolicy: Forbid #禁止并发运行
  schedule: "0 1 * * *"
  jobTemplate: #运行一个job
    spec:
      template:
        metadata:
          name: del-es-index-cronjob
        spec:
          restartPolicy: OnFailure
          imagePullSecrets:
          - name: regsecret
          containers:
          - name: curl-es
            image: shansongxian/alpine-data-curl:latest
            command:
            - "/bin/sh"
            - "-c"
            - >
              curl -X DELETE http://elasticsearch:9200/*`date +%Y.%m.%d -d "-7 days"`?pretty

  

  

删除elasticsearch大于7天前的索引

标签:type   json   format   大于   pos   search   arc   pre   http   

原文地址:https://www.cnblogs.com/shansongxian/p/10936316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!