ttl-field.asciidoc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. [[mapping-ttl-field]]
  2. === `_ttl`
  3. A lot of documents naturally come with an expiration date. Documents can
  4. therefore have a `_ttl` (time to live), which will cause the expired
  5. documents to be deleted automatically.
  6. `_ttl` accepts two parameters which are described below, every other setting will be silently ignored.
  7. [float]
  8. ==== enabled
  9. By default it is disabled, in order to enable it, the following mapping
  10. should be defined:
  11. [source,js]
  12. --------------------------------------------------
  13. {
  14. "tweet" : {
  15. "_ttl" : { "enabled" : true }
  16. }
  17. }
  18. --------------------------------------------------
  19. `_ttl` can only be enabled once and never be disabled again.
  20. [float]
  21. ==== default
  22. You can provide a per index/type default `_ttl` value as follows:
  23. [source,js]
  24. --------------------------------------------------
  25. {
  26. "tweet" : {
  27. "_ttl" : { "enabled" : true, "default" : "1d" }
  28. }
  29. }
  30. --------------------------------------------------
  31. In this case, if you don't provide a `_ttl` value in your query or in
  32. the `_source` all tweets will have a `_ttl` of one day.
  33. In case you do not specify a time unit like `d` (days), `m` (minutes),
  34. `h` (hours), `ms` (milliseconds) or `w` (weeks), milliseconds is used as
  35. default unit.
  36. If no `default` is set and no `_ttl` value is given then the document
  37. has an infinite `_ttl` and will not expire.
  38. You can dynamically update the `default` value using the put mapping
  39. API. It won't change the `_ttl` of already indexed documents but will be
  40. used for future documents.
  41. [float]
  42. ==== Note on documents expiration
  43. Expired documents will be automatically deleted regularly. You can
  44. dynamically set the `indices.ttl.interval` to fit your needs. The
  45. default value is `60s`.
  46. The deletion orders are processed by bulk. You can set
  47. `indices.ttl.bulk_size` to fit your needs. The default value is `10000`.
  48. Note that the expiration procedure handle versioning properly so if a
  49. document is updated between the collection of documents to expire and
  50. the delete order, the document won't be deleted.