Elasticsearch:使用 ILM 自动删除不起作用

Elasticsearch: Auto delition with ILM doesn't work

我想在一定时间(比如 10 秒)后删除索引,但它不起作用。我研究了很多,但我找不到与我的配置不同的东西。这是我的配置:

我的 ILM 配置:

{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "set_priority": {
            "priority": 100
          }
        }
      },
      "delete": {
        "min_age": "10s",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

我的模板:

{
  "order": 0,
  "index_patterns": ["myindex.*"],
  "settings": {
    "index": {
      "lifecycle": {
        "name": "myindex"
      }
    }
  }
}

我的索引:

{
  "job_id": 1,
  "message": "sample data",
  "@timestamp": "DATETIME"
}

然后使用以下脚本测试我的场景:

#!/bin/bash                                                                                                                                                                            
NAME=myindex

# Add ILM and template.                                                                                                                                                                
echo -n "Add policy..."
http PUT http://localhost:9200/_ilm/policy/"${NAME}" < ilm.json                                                 
echo -n "Add template..."
http PUT http://localhost:9200/_template/"${NAME}" < template.json 

# Create index.                                                                                                                                                                        
echo -n "Create index..."
http PUT http://localhost:9200/"${NAME}" | jq '.acknowledged'

# List of data stream and indices.                                                                                                                                                     
echo -n "List of data stream..."
http http://localhost:9200/_data_stream/ | jq '.data_streams'
echo "List of indices..."
http http://localhost:9200/_cat/indices/ | awk '{print }'

echo "Index ILM explain..."
http http://localhost:9200/"${NAME}"/_ilm/explain

# Insert a document.                                                                                                                                                                   
echo -n "Insert a document..."
sed "s/DATETIME/$(date +%Y-%m-%dT%H:%M:%S)/g" < index.json | http POST http://localhost:9200/"${NAME}"/_doc | jq -r ".result"

# Wait until it reaches the TTL.                                                                                                                                                       
echo "Waiting to reach the TTL..."
sleep 10 # "$(( $(jq -r .policy.phases.delete.min_age < ilm.json | sed 's/s//g') + 2 ))"                                                                                               

# Search for the data and expected to find nothing.                                                                                                                                    
echo "Search the inserted document..."
echo '{"query": {"match": {"job_id": 1}}}' | http http://localhost:9200/"${NAME}"/_search

在最后一部分,当我搜索索引时,我可以找到它。索引还在!!!

我设置了 indices.lifecycle.poll_interval 并且有效!

PUT /_cluster/settings
{
    "persistent" : {
        "indices.lifecycle.poll_interval": "5s"
    }
}

参考文献: