/
dateField.go
98 lines (90 loc) · 3.47 KB
/
dateField.go
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package mapping
// TODO: Locale?
var (
_ WithDocValues = (*DateField)(nil)
_ WithFormat = (*DateField)(nil)
_ WithIgnoreMalformed = (*DateField)(nil)
_ WithIndex = (*DateField)(nil)
_ WithNullValue = (*DateField)(nil)
_ WithStore = (*DateField)(nil)
_ WithMeta = (*DateField)(nil)
)
func NewDateField() *DateField {
return &DateField{BaseField: BaseField{MappingType: TypeDate}}
}
type DateField struct {
BaseField `bson:",inline" json:",inline"`
DocValuesParam `bson:",inline" json:",inline"`
FormatParam `bson:",inline" json:",inline"`
IgnoreMalformedParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
NullValueParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
MetaParam `bson:",inline" json:",inline"`
}
func (f DateField) Clone() Field {
n := NewDateField()
n.SetDocValues(f.DocValues())
n.SetFormat(f.Format())
n.SetIgnoreMalformed(f.IgnoreMalformed())
n.SetIndex(f.Index())
n.SetMeta(f.Meta().Clone())
n.SetNullValue(f.NullValue())
n.SetStore(f.Store())
return n
}
// DateNanoSecField is an addition to the DateField data type.
//
// However there is an important distinction between the two. The existing date
// data type stores dates in millisecond resolution. The date_nanos data type
// stores dates in nanosecond resolution, which limits its range of dates from
// roughly 1970 to 2262, as dates are still stored as a long representing
// nanoseconds since the epoch.
//
// Queries on nanoseconds are internally converted to range queries on this long
// representation, and the result of aggregations and stored fields is converted
// back to a string depending on the date format that is associated with the
// field.
//
// Date formats can be customised, but if no format is specified then it uses
// the default:
//
// "strict_date_optional_time||epoch_millis"
//
// This means that it will accept dates with optional timestamps, which conform
// to the formats supported by strict_date_optional_time including up to nine
// second fractionals or milliseconds-since-the-epoch (thus losing precision on
// the nano second part). Using strict_date_optional_time will format the result
// up to only three second fractionals. To print and parse up to nine digits of
// resolution, use strict_date_optional_time_nanos.
//
// Limitations
//
// Aggregations are still on millisecond resolution, even when using a
// date_nanos field. This limitation also affects transforms.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/date_nanos.html
type DateNanoSecField struct {
BaseField `bson:",inline" json:",inline"`
DocValuesParam `bson:",inline" json:",inline"`
FormatParam `bson:",inline" json:",inline"`
IgnoreMalformedParam `bson:",inline" json:",inline"`
IndexParam `bson:",inline" json:",inline"`
NullValueParam `bson:",inline" json:",inline"`
StoreParam `bson:",inline" json:",inline"`
MetaParam `bson:",inline" json:",inline"`
}
func (f DateNanoSecField) Clone() Field {
n := NewDateNanoSecField()
n.SetDocValues(f.DocValues())
n.SetFormat(f.Format())
n.SetIgnoreMalformed(f.IgnoreMalformed())
n.SetIndex(f.Index())
n.SetMeta(f.Meta().Clone())
n.SetNullValue(f.NullValue())
n.SetStore(f.Store())
return n
}
func NewDateNanoSecField() *DateNanoSecField {
return &DateNanoSecField{BaseField: BaseField{MappingType: TypeDateNanos}}
}