ttl-field.asciidoc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. [float]
  7. ==== enabled
  8. By default it is disabled, in order to enable it, the following mapping
  9. should be defined:
  10. [source,js]
  11. --------------------------------------------------
  12. {
  13. "tweet" : {
  14. "_ttl" : { "enabled" : true }
  15. }
  16. }
  17. --------------------------------------------------
  18. [float]
  19. ==== store / index
  20. By default the `_ttl` field has `store` set to `true` and `index` set to
  21. `not_analyzed`. Note that `index` property has to be set to
  22. `not_analyzed` in order for the purge process to work.
  23. [float]
  24. ==== default
  25. You can provide a per index/type default `_ttl` value as follows:
  26. [source,js]
  27. --------------------------------------------------
  28. {
  29. "tweet" : {
  30. "_ttl" : { "enabled" : true, "default" : "1d" }
  31. }
  32. }
  33. --------------------------------------------------
  34. In this case, if you don't provide a `_ttl` value in your query or in
  35. the `_source` all tweets will have a `_ttl` of one day.
  36. In case you do not specify a time unit like `d` (days), `m` (minutes),
  37. `h` (hours), `ms` (milliseconds) or `w` (weeks), milliseconds is used as
  38. default unit.
  39. If no `default` is set and no `_ttl` value is given then the document
  40. has an infinite `_ttl` and will not expire.
  41. You can dynamically update the `default` value using the put mapping
  42. API. It won't change the `_ttl` of already indexed documents but will be
  43. used for future documents.
  44. [float]
  45. ==== Note on documents expiration
  46. Expired documents will be automatically deleted regularly. You can
  47. dynamically set the `indices.ttl.interval` to fit your needs. The
  48. default value is `60s`.
  49. The deletion orders are processed by bulk. You can set
  50. `indices.ttl.bulk_size` to fit your needs. The default value is `10000`.
  51. Note that the expiration procedure handle versioning properly so if a
  52. document is updated between the collection of documents to expire and
  53. the delete order, the document won't be deleted.