-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpit.go
47 lines (42 loc) · 1.35 KB
/
pit.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
// Copyright 2012-present Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package elastic
// PointInTime is a lightweight view into the state of the data that existed
// when initiated. It can be created with OpenPointInTime API and be used
// when searching, e.g. in Search API or with SearchSource.
type PointInTime struct {
// Id that uniquely identifies the point in time, as created with the
// OpenPointInTime API.
Id string `json:"id,omitempty"`
// KeepAlive is the time for which this specific PointInTime will be
// kept alive by Elasticsearch.
KeepAlive string `json:"keep_alive,omitempty"`
}
// NewPointInTime creates a new PointInTime.
func NewPointInTime(id string) *PointInTime {
return &PointInTime{
Id: id,
}
}
// NewPointInTimeWithKeepAlive creates a new PointInTime with the given
// time to keep alive.
func NewPointInTimeWithKeepAlive(id, keepAlive string) *PointInTime {
return &PointInTime{
Id: id,
KeepAlive: keepAlive,
}
}
// Source generates the JSON serializable fragment for the PointInTime.
func (pit *PointInTime) Source() (interface{}, error) {
if pit == nil {
return nil, nil
}
m := map[string]interface{}{
"id": pit.Id,
}
if pit.KeepAlive != "" {
m["keep_alive"] = pit.KeepAlive
}
return m, nil
}