检查发生在旧 Elasticsearch 索引上的写入

Check writes happening to an old Elasticsearch index

现在由于 Elasticsearch 集群上的磁盘 space 问题,我们需要清理未使用的索引,但我们要加倍确保旧索引不会以任何方式被使用。

我们使用了 https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html,但它并不能提供最近是否使用过索引的可靠证据。

最好的解决方案是来自 ES 的一些 API,我们可以通过它快速确定和删除旧索引。

您可以使用 index stats API 来查看自上次重新启动后给定索引是否处理了搜索或索引请求。

GET index/_stats
=>
  "_all": {
    "primaries": {
      "docs": {
        "count": 396885916,
        "deleted": 1712210
      },
      "store": {
        "size_in_bytes": 207383595268,
        "throttle_time_in_millis": 0
      },
      "indexing": {
        "index_total": 8,               <-- writes are happening if you see this increase
        "index_time_in_millis": 41,
        "index_current": 0,
        "index_failed": 0,
        "delete_total": 0,
        "delete_time_in_millis": 0,
        "delete_current": 0,
        "noop_update_total": 0,
        "is_throttled": false,
        "throttle_time_in_millis": 0
      },
      "get": {
        "total": 0,
        "time_in_millis": 0,
        "exists_total": 0,
        "exists_time_in_millis": 0,
        "missing_total": 0,
        "missing_time_in_millis": 0,
        "current": 0
      },
      "search": {
        "open_contexts": 7,
        "query_total": 30238,           <-- reads are happening if you see this increase
        "query_time_in_millis": 254000,
        "query_current": 0,
        "fetch_total": 816,
        "fetch_time_in_millis": 25997,
        "fetch_current": 0,
        "scroll_total": 7637,
        "scroll_time_in_millis": 686963111,
        "scroll_current": 7,
        "suggest_total": 0,
        "suggest_time_in_millis": 0,
        "suggest_current": 0
      },