Skip to content

Commit

Permalink
PointInTime API: Make keep alive optional
Browse files Browse the repository at this point in the history
The keep alive parameter for the PIT is optional.

Close #1524
  • Loading branch information
olivere committed Aug 30, 2021
1 parent a5767e3 commit d0ea877
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions pit.go
Expand Up @@ -17,7 +17,15 @@ type PointInTime struct {
}

// NewPointInTime creates a new PointInTime.
func NewPointInTime(id, keepAlive string) *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,
Expand All @@ -29,8 +37,11 @@ func (pit *PointInTime) Source() (interface{}, error) {
if pit == nil {
return nil, nil
}
return map[string]interface{}{
"id": pit.Id,
"keep_alive": pit.KeepAlive,
}, nil
m := map[string]interface{}{
"id": pit.Id,
}
if pit.KeepAlive != "" {
m["keep_alive"] = pit.KeepAlive
}
return m, nil
}
2 changes: 1 addition & 1 deletion pit_test.go
Expand Up @@ -76,7 +76,7 @@ func TestPointInTimeLifecycle(t *testing.T) {
searchResult, err := client.Search().
// Index(testIndexName). // <-- you may not use indices with PointInTime!
Query(NewMatchAllQuery()).
PointInTime(NewPointInTime(pitResp.Id, "1m")).
PointInTime(NewPointInTimeWithKeepAlive(pitResp.Id, "1m")).
Size(100).
Pretty(true).
Do(context.TODO())
Expand Down
2 changes: 1 addition & 1 deletion search_source_test.go
Expand Up @@ -320,7 +320,7 @@ func TestSearchSourceSeqNoAndPrimaryTerm(t *testing.T) {
func TestSearchSourcePointInTime(t *testing.T) {
matchAllQ := NewMatchAllQuery()
builder := NewSearchSource().Query(matchAllQ).PointInTime(
NewPointInTime("pit_id", "2m"),
NewPointInTimeWithKeepAlive("pit_id", "2m"),
)
src, err := builder.Source()
if err != nil {
Expand Down

0 comments on commit d0ea877

Please sign in to comment.