Skip to content

Commit 068fe43

Browse files
authored
bulk_indexer: Remove ES field mapper field preview (#190)
* bulk_indexer: Remove ES field mapper field preview * fix: update code * Update bulk_indexer.go
1 parent c9a2215 commit 068fe43

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

appender_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
747747
for i, item := range result.Items {
748748
itemResp := item["create"]
749749
itemResp.Index = "an_index"
750-
switch i % 3 {
750+
switch i % 4 {
751751
case 0:
752752
itemResp.Error.Type = "error_type"
753753
itemResp.Error.Reason = "error_reason_even. Preview of field's value: 'abc def ghi'"
@@ -757,6 +757,10 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
757757
case 2:
758758
itemResp.Error.Type = "unavailable_shards_exception"
759759
itemResp.Error.Reason = "this reason should not be logged"
760+
case 3:
761+
itemResp.Error.Type = "x_content_parse_exception"
762+
itemResp.Error.Reason = "this reason should not be logged"
763+
760764
}
761765
item["create"] = itemResp
762766
}
@@ -772,7 +776,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
772776
require.NoError(t, err)
773777
defer indexer.Close(context.Background())
774778

775-
const N = 3 * 2
779+
const N = 4 * 2
776780
for i := 0; i < N; i++ {
777781
addMinimalDoc(t, indexer, "logs-foo-testing")
778782
}
@@ -790,6 +794,8 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
790794
assert.Equal(t, int64(2), entries[1].Context[0].Integer)
791795
assert.Equal(t, "failed to index documents in 'an_index' (unavailable_shards_exception): ", entries[2].Message)
792796
assert.Equal(t, int64(2), entries[2].Context[0].Integer)
797+
assert.Equal(t, "failed to index documents in 'an_index' (x_content_parse_exception): ", entries[3].Message)
798+
assert.Equal(t, int64(2), entries[3].Context[0].Integer)
793799
}
794800

795801
func TestAppenderRetryLimit(t *testing.T) {

bulk_indexer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ func init() {
139139
case "type":
140140
item.Error.Type = i.ReadString()
141141
case "reason":
142+
reason := i.ReadString()
142143
// Match Elasticsearch field mapper field value:
143144
// failed to parse field [%s] of type [%s] in %s. Preview of field's value: '%s'
144145
// https://github.com/elastic/elasticsearch/blob/588eabe185ad319c0268a13480465966cef058cd/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java#L234
145146
item.Error.Reason, _, _ = strings.Cut(
146-
i.ReadString(), ". Preview",
147+
reason, ". Preview",
147148
)
148149
default:
149150
i.Skip()
@@ -155,8 +156,8 @@ func init() {
155156
}
156157
return true
157158
})
158-
// For unavailable_shards_exception, remove item.Error.Reason as it may contain sensitive request content.
159-
if item.Error.Type == "unavailable_shards_exception" {
159+
// For specific exceptions, remove item.Error.Reason as it may contain sensitive request content.
160+
if item.Error.Type == "unavailable_shards_exception" || item.Error.Type == "x_content_parse_exception" {
160161
item.Error.Reason = ""
161162
}
162163

0 commit comments

Comments
 (0)