WARNING: Version 2.3 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
_timestamp field
edit_timestamp
field
editDeprecated in 2.0.0-beta2.
The _timestamp
field is deprecated. Instead, use a normal date
field and set its value explicitly
The _timestamp
field, when enabled, allows a timestamp to be indexed and
stored with a document. The timestamp may be specified manually, generated
automatically, or set to a default value:
PUT my_index { "mappings": { "my_type": { "_timestamp": { "enabled": true } } } } PUT my_index/my_type/1?timestamp=2015-01-01 { "text": "Timestamp as a formatted date" } PUT my_index/my_type/2?timestamp=1420070400000 { "text": "Timestamp as milliseconds since the epoch" } PUT my_index/my_type/3 { "text": "Autogenerated timestamp set to now()" }
Enable the |
|
Set the timestamp manually with a formatted date. |
|
Set the timestamp with milliseconds since the epoch. |
|
Auto-generates a timestamp with now(). |
The behaviour of the _timestamp
field can be configured with the following parameters:
-
default
- A default value to be used if none is provided. Defaults to now().
-
format
-
The date format (or formats) to use when parsing timestamps. Defaults to
epoch_millis||strictDateOptionalTime
. -
ignore_missing
-
If
true
(default), replace missing timestamps with thedefault
value. Iffalse
, throw an exception.
The value of the _timestamp
field is accessible in queries, aggregations, scripts,
and when sorting:
GET my_index/_search { "query": { "range": { "_timestamp": { "gte": "2015-01-01" } } }, "aggs": { "Timestamps": { "terms": { "field": "_timestamp", "size": 10 } } }, "sort": [ { "_timestamp": { "order": "desc" } } ], "script_fields": { "Timestamp": { "script": "doc['_timestamp']" } } }
Querying on the |
|
Aggregating on the |
|
Sorting on the |
|
Accessing the |