Skip to content

Commit

Permalink
DX: Only add require_alias parameter if its true, prevents requiremen…
Browse files Browse the repository at this point in the history
…t for a pointer
  • Loading branch information
Anaethelion committed Jun 6, 2023
1 parent ae9cd05 commit 4ea9db9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
12 changes: 7 additions & 5 deletions esutil/bulk_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type BulkIndexerConfig struct {
Pretty bool
Refresh string
Routing string
RequireAlias *bool
RequireAlias bool
Source []string
SourceExcludes []string
SourceIncludes []string
Expand All @@ -102,7 +102,7 @@ type BulkIndexerItem struct {
Action string
DocumentID string
Routing string
RequireAlias *bool
RequireAlias bool
Version *int64
VersionType string
Body io.ReadSeeker
Expand Down Expand Up @@ -168,12 +168,12 @@ func (item *BulkIndexerItem) marshallMeta() {
item.meta.Write(strconv.AppendInt(aux, int64(*item.RetryOnConflict), 10))
aux = aux[:0]
}
if item.RequireAlias != nil {
if item.RequireAlias {
if item.DocumentID != "" || item.Routing != "" || item.Index != "" || item.RetryOnConflict != nil {
item.meta.WriteString(",")
}
item.meta.WriteString(`"require_alias":`)
item.meta.Write(strconv.AppendBool(aux, *item.RequireAlias))
item.meta.Write(strconv.AppendBool(aux, item.RequireAlias))
aux = aux[:0]
}

Expand Down Expand Up @@ -530,7 +530,6 @@ func (w *worker) flushBuffer(ctx context.Context) error {
Pipeline: w.bi.config.Pipeline,
Refresh: w.bi.config.Refresh,
Routing: w.bi.config.Routing,
RequireAlias: w.bi.config.RequireAlias,
Source: w.bi.config.Source,
SourceExcludes: w.bi.config.SourceExcludes,
SourceIncludes: w.bi.config.SourceIncludes,
Expand All @@ -543,6 +542,9 @@ func (w *worker) flushBuffer(ctx context.Context) error {
FilterPath: w.bi.config.FilterPath,
Header: w.bi.config.Header.Clone(),
}
if w.bi.config.RequireAlias {
req.RequireAlias = &w.bi.config.RequireAlias
}

// Add Header and MetaHeader to config if not already set
if req.Header == nil {
Expand Down
3 changes: 1 addition & 2 deletions esutil/bulk_indexer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"compress/gzip"
"context"
"fmt"
"github.com/elastic/go-elasticsearch/v8/esapi"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -285,7 +284,7 @@ func TestBulkIndexerIntegration(t *testing.T) {
Index: alias,
DocumentID: strconv.Itoa(i),
Body: strings.NewReader(body),
RequireAlias: esapi.BoolPtr(true),
RequireAlias: true,
OnSuccess: func(ctx context.Context, item esutil.BulkIndexerItem, item2 esutil.BulkIndexerResponseItem) {
atomic.AddUint64(&countSuccessful, 1)
},
Expand Down
4 changes: 2 additions & 2 deletions esutil/bulk_indexer_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ func TestBulkIndexer(t *testing.T) {
Action: "index",
DocumentID: "42",
Index: "test",
RequireAlias: esapi.BoolPtr(true),
RequireAlias: true,
}},
`{"index":{"_id":"42","_index":"test","require_alias":true}}` + "\n",
},
Expand All @@ -684,7 +684,7 @@ func TestBulkIndexer(t *testing.T) {
Index: "test",
Version: &v,
VersionType: "external",
RequireAlias: esapi.BoolPtr(true),
RequireAlias: true,
}},
`{"index":{"_id":"42","version":23,"version_type":"external","_index":"test","require_alias":true}}` + "\n",
},
Expand Down

0 comments on commit 4ea9db9

Please sign in to comment.