【问题标题】:Elasticsearch: Auto delition with ILM doesn't workElasticsearch:使用 ILM 的自动删除不起作用
【发布时间】:2021-07-31 15:18:54
【问题描述】:

我想在特定时间(比如 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 $3}'

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

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

【问题讨论】:

标签: elasticsearch elastic-stack ttl


【解决方案1】:

我设置了indices.lifecycle.poll_interval,它可以工作!

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

参考资料:

【讨论】:

    猜你喜欢
    • 2020-05-08
    • 2019-10-27
    • 2021-02-19
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 2020-08-12
    • 1970-01-01
    相关资源
    最近更新 更多