2013-08-28 19:24:34 -04:00
|
|
|
[[mapping-timestamp-field]]
|
|
|
|
=== `_timestamp`
|
|
|
|
|
|
|
|
The `_timestamp` field allows to automatically index the timestamp of a
|
|
|
|
document. It can be provided externally via the index request or in the
|
|
|
|
`_source`. If it is not provided externally it will be automatically set
|
2014-07-25 09:14:31 -04:00
|
|
|
to a <<mapping-timestamp-field-default,default date>>.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
==== enabled
|
|
|
|
|
2014-03-07 08:21:45 -05:00
|
|
|
By default it is disabled. In order to enable it, the following mapping
|
2013-08-28 19:24:34 -04:00
|
|
|
should be defined:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"tweet" : {
|
|
|
|
"_timestamp" : { "enabled" : true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== store / index
|
|
|
|
|
2014-10-17 09:34:46 -04:00
|
|
|
By default the `_timestamp` field has `store` set to `true` and `index`
|
2013-08-28 19:24:34 -04:00
|
|
|
set to `not_analyzed`. It can be queried as a standard date field.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== path
|
|
|
|
|
|
|
|
The `_timestamp` value can be provided as an external value when
|
|
|
|
indexing. But, it can also be automatically extracted from the document
|
|
|
|
to index based on a `path`. For example, having the following mapping:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"tweet" : {
|
|
|
|
"_timestamp" : {
|
|
|
|
"enabled" : true,
|
|
|
|
"path" : "post_date"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Will cause `2009-11-15T14:12:12` to be used as the timestamp value for:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"message" : "You know, for Search",
|
|
|
|
"post_date" : "2009-11-15T14:12:12"
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2014-07-01 07:37:38 -04:00
|
|
|
Note, using `path` without explicit timestamp value provided requires an
|
2013-08-28 19:24:34 -04:00
|
|
|
additional (though quite fast) parsing phase.
|
|
|
|
|
|
|
|
[float]
|
2014-07-25 09:14:31 -04:00
|
|
|
[[mapping-timestamp-field-format]]
|
2013-08-28 19:24:34 -04:00
|
|
|
==== format
|
|
|
|
|
|
|
|
You can define the <<mapping-date-format,date
|
|
|
|
format>> used to parse the provided timestamp value. For example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"tweet" : {
|
|
|
|
"_timestamp" : {
|
|
|
|
"enabled" : true,
|
|
|
|
"path" : "post_date",
|
|
|
|
"format" : "YYYY-MM-dd"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Note, the default format is `dateOptionalTime`. The timestamp value will
|
|
|
|
first be parsed as a number and if it fails the format will be tried.
|
2014-07-25 09:14:31 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
[[mapping-timestamp-field-default]]
|
|
|
|
==== default
|
|
|
|
|
|
|
|
You can define a default value for when timestamp is not provided
|
|
|
|
within the index request or in the `_source` document.
|
|
|
|
|
|
|
|
By default, the default value is `now` which means the date the document was processed by the indexing chain.
|
|
|
|
|
2014-12-30 11:32:50 -05:00
|
|
|
You can reject documents which do not provide a `timestamp` value by setting `ignore_missing` to false (default to `true`):
|
2014-07-25 09:14:31 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"tweet" : {
|
|
|
|
"_timestamp" : {
|
|
|
|
"enabled" : true,
|
2014-12-30 11:32:50 -05:00
|
|
|
"ignore_missing" : false
|
2014-07-25 09:14:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
You can also set the default value to any date respecting <<mapping-timestamp-field-format,timestamp format>>:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"tweet" : {
|
|
|
|
"_timestamp" : {
|
|
|
|
"enabled" : true,
|
|
|
|
"format" : "YYYY-MM-dd",
|
|
|
|
"default" : "1970-01-01"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2014-11-21 20:23:38 -05:00
|
|
|
If you don't provide any timestamp value, _timestamp will be set to this default value.
|
2014-07-25 09:14:31 -04:00
|
|
|
|
2014-12-30 11:32:50 -05:00
|
|
|
In elasticsearch 1.4, we allowed setting explicitly `"default":null` which is not possible anymore
|
2015-01-29 13:17:41 -05:00
|
|
|
as we added a new `ignore_missing` setting.
|
2014-12-30 11:32:50 -05:00
|
|
|
When reading an index created with elasticsearch 1.4 and using this, we automatically update it by
|
|
|
|
removing `"default": null` and setting `"ignore_missing": false`
|
|
|
|
|