timestamp-field.asciidoc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 the date the document was processed by the indexing chain.
  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 `false` 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 require an
  48. additional (though quite fast) parsing phase.
  49. [float]
  50. ==== format
  51. You can define the <<mapping-date-format,date
  52. format>> used to parse the provided timestamp value. For example:
  53. [source,js]
  54. --------------------------------------------------
  55. {
  56. "tweet" : {
  57. "_timestamp" : {
  58. "enabled" : true,
  59. "path" : "post_date",
  60. "format" : "YYYY-MM-dd"
  61. }
  62. }
  63. }
  64. --------------------------------------------------
  65. Note, the default format is `dateOptionalTime`. The timestamp value will
  66. first be parsed as a number and if it fails the format will be tried.