简体   繁体   English

按周期自动删除索引日志 ElasticSearch

[英]Auto Delete index log ElasticSearch by period

How can i configure ElasticSearch to delete logs passed 1 month, or if there is no sush conf, how can i call api delete for this purpose from java我如何配置 ElasticSearch 以删除过去 1 个月的日志,或者如果没有 sush conf,我如何从 Java 调用 api delete 为此目的

Thank you谢谢

Have you tried using the Delete by query API ?您是否尝试过使用按查询删除 API

This post also discusses how to go about doing so for 10 days. 这篇文章还讨论了如何在 10 天内这样做。 You could try it with 30 days instead.您可以尝试使用 30 天。

Reading over these, you should get an idea of what to do.阅读这些,你应该知道该怎么做。 I do not know the exact answer but I hope this at least helps.我不知道确切的答案,但我希望这至少会有所帮助。

This is the sample index with 2 documents.这是包含 2 个文档的示例索引。

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "sample",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "created" : "06/18/2021"
        }
      },
      {
        "_index" : "sample",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "created" : "06/17/2021"
        }
      }
    ]
  }
}

Now you can use delete by query现在您可以使用按查询删除

POST /sample/_delete_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "created": {
              "lte": "now-30d/d",
              "format": "MM/dd/yyyy"
            }
          }
        }
      ]
    }
  }
}

Output:输出:

{
  "took" : 8,
  "timed_out" : false,
  "total" : 2,
  "deleted" : 2,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

You will see Total : 2 and Deleted : 2 Hope this helps @java_dev您将看到Total : 2 和Deleted : 2 希望这有助于@java_dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM