timestamp-field.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. [[mapping-timestamp-field]]
  2. === `_timestamp`
  3. The `_timestamp` field allows to automatically index the timestamp of a
  4. document. It can be provided externally via the index request or in the
  5. `_source`. If it is not provided externally it will be automatically set
  6. to a <<mapping-timestamp-field-default,default date>>.
  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. "_timestamp" : { "enabled" : true }
  16. }
  17. }
  18. --------------------------------------------------
  19. [float]
  20. ==== store / index
  21. By default the `_timestamp` field has `store` set to `true` and `index`
  22. set to `not_analyzed`. It can be queried as a standard date field.
  23. [float]
  24. ==== path
  25. The `_timestamp` value can be provided as an external value when
  26. indexing. But, it can also be automatically extracted from the document
  27. to index based on a `path`. For example, having the following mapping:
  28. [source,js]
  29. --------------------------------------------------
  30. {
  31. "tweet" : {
  32. "_timestamp" : {
  33. "enabled" : true,
  34. "path" : "post_date"
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. Will cause `2009-11-15T14:12:12` to be used as the timestamp value for:
  40. [source,js]
  41. --------------------------------------------------
  42. {
  43. "message" : "You know, for Search",
  44. "post_date" : "2009-11-15T14:12:12"
  45. }
  46. --------------------------------------------------
  47. Note, using `path` without explicit timestamp value provided requires an
  48. additional (though quite fast) parsing phase.
  49. [float]
  50. [[mapping-timestamp-field-format]]
  51. ==== format
  52. You can define the <<mapping-date-format,date
  53. format>> used to parse the provided timestamp value. For example:
  54. [source,js]
  55. --------------------------------------------------
  56. {
  57. "tweet" : {
  58. "_timestamp" : {
  59. "enabled" : true,
  60. "path" : "post_date",
  61. "format" : "YYYY-MM-dd"
  62. }
  63. }
  64. }
  65. --------------------------------------------------
  66. Note, the default format is `dateOptionalTime`. The timestamp value will
  67. first be parsed as a number and if it fails the format will be tried.
  68. [float]
  69. [[mapping-timestamp-field-default]]
  70. ==== default
  71. You can define a default value for when timestamp is not provided
  72. within the index request or in the `_source` document.
  73. By default, the default value is `now` which means the date the document was processed by the indexing chain.
  74. You can reject documents which do not provide a `timestamp` value by setting `ignore_missing` to false (default to `true`):
  75. [source,js]
  76. --------------------------------------------------
  77. {
  78. "tweet" : {
  79. "_timestamp" : {
  80. "enabled" : true,
  81. "ignore_missing" : false
  82. }
  83. }
  84. }
  85. --------------------------------------------------
  86. You can also set the default value to any date respecting <<mapping-timestamp-field-format,timestamp format>>:
  87. [source,js]
  88. --------------------------------------------------
  89. {
  90. "tweet" : {
  91. "_timestamp" : {
  92. "enabled" : true,
  93. "format" : "YYYY-MM-dd",
  94. "default" : "1970-01-01"
  95. }
  96. }
  97. }
  98. --------------------------------------------------
  99. If you don't provide any timestamp value, _timestamp will be set to this default value.
  100. coming[1.5.0]
  101. In elasticsearch 1.4, we allowed setting explicitly `"default":null` which is not possible anymore
  102. as we added a new `ignore_missing` setting.
  103. When reading an index created with elasticsearch 1.4 and using this, we automatically update it by
  104. removing `"default": null` and setting `"ignore_missing": false`