| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | [[mapping-timestamp-field]]=== `_timestamp`The `_timestamp` field allows to automatically index the timestamp of adocument. It can be provided externally via the index request or in the`_source`. If it is not provided externally it will be automatically setto a <<mapping-timestamp-field-default,default date>>.[float]==== enabledBy default it is disabled. In order to enable it, the following mappingshould be defined:[source,js]--------------------------------------------------{    "tweet" : {        "_timestamp" : { "enabled" : true }    }}--------------------------------------------------[float]==== store / indexBy default the `_timestamp` field has `store` set to `true` and `index`set to `not_analyzed`. It can be queried as a standard date field.[float]==== pathThe `_timestamp` value can be provided as an external value whenindexing. But, it can also be automatically extracted from the documentto 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"}--------------------------------------------------Note, using `path` without explicit timestamp value provided requires anadditional (though quite fast) parsing phase.[float][[mapping-timestamp-field-format]]==== formatYou can define the <<mapping-date-format,dateformat>> 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 willfirst be parsed as a number and if it fails the format will be tried.[float][[mapping-timestamp-field-default]]==== defaultYou can define a default value for when timestamp is not providedwithin 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.You can reject documents which do not provide a `timestamp` value by setting `ignore_missing` to false (default to `true`):[source,js]--------------------------------------------------{    "tweet" : {        "_timestamp" : {            "enabled" : true,            "ignore_missing" : false        }    }}--------------------------------------------------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"        }    }}--------------------------------------------------If you don't provide any timestamp value, _timestamp will be set to this default value.In elasticsearch 1.4, we allowed setting explicitly `"default":null` which is not possible anymoreas we added a new `ignore_missing` setting.When reading an index created with elasticsearch 1.4 and using this, we automatically update it byremoving `"default": null` and setting `"ignore_missing": false`
 |