首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch: ILM的自动删除不起作用

Elasticsearch: ILM的自动删除不起作用
EN

Stack Overflow用户
提问于 2021-07-31 15:18:54
回答 1查看 231关注 0票数 1

我想在一定时间后(比如10s)删除一个索引,但它不起作用。我做了很多研究,但找不到和我吐露的东西不同的东西。以下是我的心声:

我的ILM配置:

代码语言:javascript
复制
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "set_priority": {
            "priority": 100
          }
        }
      },
      "delete": {
        "min_age": "10s",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

我的模板:

代码语言:javascript
复制
{
  "order": 0,
  "index_patterns": ["myindex.*"],
  "settings": {
    "index": {
      "lifecycle": {
        "name": "myindex"
      }
    }
  }
}

我的索引:

代码语言:javascript
复制
{
  "job_id": 1,
  "message": "sample data",
  "@timestamp": "DATETIME"
}

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

代码语言:javascript
复制
#!/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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-03 17:19:17

我设置了indices.lifecycle.poll_interval,它起作用了!

代码语言:javascript
复制
PUT /_cluster/settings
{
    "persistent" : {
        "indices.lifecycle.poll_interval": "5s"
    }
}

参考文献:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68603389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档