ElasticSearch文档过期时间设置

新建索引启用过期设置:
PUT testindex
{
    "mappings": {
    "testtype": {
      "_ttl": {
        "enabled": true
      }
    }
  }
}

插入文档:
PUT testindex/testtype/1?ttl=10m 
{
  "text": "Will expire in 10 minutes"
}

如果不添加ttl过期参数则文档默认不过期,可以在创建索引时加入默认过期时间:
PUT my_index
{
  "mappings": {
    "my_type": {
      "_ttl": {
        "enabled": true,
        "default": "5m"
      }
    }
  }
}

时间单位说明:
  d 
  ms(默认) 毫秒
m 分钟


相关参数备注:
indices.ttl.interval:文档扫描周期(默认为60秒)
indices.ttl.bulk_size:批量删除过期文档数量(默认为10000)
detect_noop:如果此参数设置为true时,单纯修改文档的ttl不会影响这个文档的过期时间,修改文档字段时会影响,在2.1版本中默认值为true

猜你喜欢

转载自zhaoshengbo.iteye.com/blog/2285503