timestamp-field.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. [[mapping-timestamp-field]]
  2. === `_timestamp`
  3. The `_timestamp` field allows to automatically index the timestamp of a
  4. document. If it is not provided it will be automatically set
  5. to a <<mapping-timestamp-field-default,default date>>.
  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. "_timestamp" : { "enabled" : true }
  15. }
  16. }
  17. --------------------------------------------------
  18. [float]
  19. [[mapping-timestamp-field-format]]
  20. ==== format
  21. You can define the <<mapping-date-format,date
  22. format>> used to parse the provided timestamp value. For example:
  23. [source,js]
  24. --------------------------------------------------
  25. {
  26. "tweet" : {
  27. "_timestamp" : {
  28. "enabled" : true,
  29. "path" : "post_date",
  30. "format" : "YYYY-MM-dd"
  31. }
  32. }
  33. }
  34. --------------------------------------------------
  35. Note, the default format is `epoch_millis||strictDateOptionalTime`. The timestamp value will
  36. first be parsed as a number and if it fails the format will be tried.
  37. [float]
  38. [[mapping-timestamp-field-default]]
  39. ==== default
  40. You can define a default value for when timestamp is not provided
  41. within the index request or in the `_source` document.
  42. By default, the default value is `now` which means the date the document was processed by the indexing chain.
  43. You can reject documents which do not provide a `timestamp` value by setting `ignore_missing` to false (default to `true`):
  44. [source,js]
  45. --------------------------------------------------
  46. {
  47. "tweet" : {
  48. "_timestamp" : {
  49. "enabled" : true,
  50. "ignore_missing" : false
  51. }
  52. }
  53. }
  54. --------------------------------------------------
  55. You can also set the default value to any date respecting <<mapping-timestamp-field-format,timestamp format>>:
  56. [source,js]
  57. --------------------------------------------------
  58. {
  59. "tweet" : {
  60. "_timestamp" : {
  61. "enabled" : true,
  62. "format" : "YYYY-MM-dd",
  63. "default" : "1970-01-01"
  64. }
  65. }
  66. }
  67. --------------------------------------------------
  68. If you don't provide any timestamp value, _timestamp will be set to this default value.
  69. In elasticsearch 1.4, we allowed setting explicitly `"default":null` which is not possible anymore
  70. as we added a new `ignore_missing` setting.
  71. When reading an index created with elasticsearch 1.4 and using this, we automatically update it by
  72. removing `"default": null` and setting `"ignore_missing": false`