| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | [[mapping-ttl-field]]=== `_ttl`A lot of documents naturally come with an expiration date. Documents cantherefore have a `_ttl` (time to live), which will cause the expireddocuments to be deleted automatically.[float]==== enabledBy default it is disabled, in order to enable it, the following mappingshould be defined:[source,js]--------------------------------------------------{    "tweet" : {        "_ttl" : { "enabled" : true }    }}--------------------------------------------------[float]==== store / indexBy default the `_ttl` field has `store` set to `yes` and `index` set to`not_analyzed`. Note that `index` property has to be set to`not_analyzed` in order for the purge process to work.[float]==== defaultYou can provide a per index/type default `_ttl` value as follows:[source,js]--------------------------------------------------{    "tweet" : {        "_ttl" : { "enabled" : true, "default" : "1d" }    }}--------------------------------------------------In this case, if you don't provide a `_ttl` value in your query or inthe `_source` all tweets will have a `_ttl` of one day.In case you do not specify a time unit like `d` (days), `m` (minutes),`h` (hours), `ms` (milliseconds) or `w` (weeks), milliseconds is used asdefault unit.If no `default` is set and no `_ttl` value is given then the documenthas an infinite `_ttl` and will not expire.You can dynamically update the `default` value using the put mappingAPI. It won't change the `_ttl` of already indexed documents but will beused for future documents.[float]==== Note on documents expirationExpired documents will be automatically deleted regularly. You candynamically set the `indices.ttl.interval` to fit your needs. Thedefault value is `60s`.The deletion orders are processed by bulk. You can set`indices.ttl.bulk_size` to fit your needs. The default value is `10000`.Note that the expiration procedure handle versioning properly so if adocument is updated between the collection of documents to expire andthe delete order, the document won't be deleted.
 |