summaryrefslogtreecommitdiff
path: root/docs/reference/mapping/fields/timestamp-field.asciidoc
blob: 97bca8dfde541de65cf0f8bca3200bcd7f10b635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[[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
to the date the document was processed by the indexing chain.

[float]
==== enabled

By default it is disabled, in order to enable it, the following mapping
should be defined:

[source,js]
--------------------------------------------------
{
    "tweet" : {
        "_timestamp" : { "enabled" : true }
    }
}
--------------------------------------------------

[float]
==== store / index

By default the `_timestamp` field has `store` set to `false` and `index`
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"
}
--------------------------------------------------

Note, using `path` without explicit timestamp value provided require an
additional (though quite fast) parsing phase.

[float]
==== 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.