Skip to content

Commit d0ea877

Browse files
committed
PointInTime API: Make keep alive optional
The keep alive parameter for the PIT is optional. Close #1524
1 parent a5767e3 commit d0ea877

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

pit.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ type PointInTime struct {
1717
}
1818

1919
// NewPointInTime creates a new PointInTime.
20-
func NewPointInTime(id, keepAlive string) *PointInTime {
20+
func NewPointInTime(id string) *PointInTime {
21+
return &PointInTime{
22+
Id: id,
23+
}
24+
}
25+
26+
// NewPointInTimeWithKeepAlive creates a new PointInTime with the given
27+
// time to keep alive.
28+
func NewPointInTimeWithKeepAlive(id, keepAlive string) *PointInTime {
2129
return &PointInTime{
2230
Id: id,
2331
KeepAlive: keepAlive,
@@ -29,8 +37,11 @@ func (pit *PointInTime) Source() (interface{}, error) {
2937
if pit == nil {
3038
return nil, nil
3139
}
32-
return map[string]interface{}{
33-
"id": pit.Id,
34-
"keep_alive": pit.KeepAlive,
35-
}, nil
40+
m := map[string]interface{}{
41+
"id": pit.Id,
42+
}
43+
if pit.KeepAlive != "" {
44+
m["keep_alive"] = pit.KeepAlive
45+
}
46+
return m, nil
3647
}

pit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestPointInTimeLifecycle(t *testing.T) {
7676
searchResult, err := client.Search().
7777
// Index(testIndexName). // <-- you may not use indices with PointInTime!
7878
Query(NewMatchAllQuery()).
79-
PointInTime(NewPointInTime(pitResp.Id, "1m")).
79+
PointInTime(NewPointInTimeWithKeepAlive(pitResp.Id, "1m")).
8080
Size(100).
8181
Pretty(true).
8282
Do(context.TODO())

search_source_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func TestSearchSourceSeqNoAndPrimaryTerm(t *testing.T) {
320320
func TestSearchSourcePointInTime(t *testing.T) {
321321
matchAllQ := NewMatchAllQuery()
322322
builder := NewSearchSource().Query(matchAllQ).PointInTime(
323-
NewPointInTime("pit_id", "2m"),
323+
NewPointInTimeWithKeepAlive("pit_id", "2m"),
324324
)
325325
src, err := builder.Source()
326326
if err != nil {

0 commit comments

Comments
 (0)