_timestamp fieldedit

Deprecated 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 _timestamp field with default settings.

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 the default value. If false, 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 _timestamp field

Aggregating on the _timestamp field

Sorting on the _timestamp field

Accessing the _timestamp field in scripts (inline scripts must be enabled for this example to work)