diff --git a/appender_test.go b/appender_test.go index c226b3a..d8c0db9 100644 --- a/appender_test.go +++ b/appender_test.go @@ -747,7 +747,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) { for i, item := range result.Items { itemResp := item["create"] itemResp.Index = "an_index" - switch i % 3 { + switch i % 4 { case 0: itemResp.Error.Type = "error_type" itemResp.Error.Reason = "error_reason_even. Preview of field's value: 'abc def ghi'" @@ -757,6 +757,10 @@ func TestAppenderIndexFailedLogging(t *testing.T) { case 2: itemResp.Error.Type = "unavailable_shards_exception" itemResp.Error.Reason = "this reason should not be logged" + case 3: + itemResp.Error.Type = "x_content_parse_exception" + itemResp.Error.Reason = "this reason should not be logged" + } item["create"] = itemResp } @@ -772,7 +776,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) { require.NoError(t, err) defer indexer.Close(context.Background()) - const N = 3 * 2 + const N = 4 * 2 for i := 0; i < N; i++ { addMinimalDoc(t, indexer, "logs-foo-testing") } @@ -790,6 +794,8 @@ func TestAppenderIndexFailedLogging(t *testing.T) { assert.Equal(t, int64(2), entries[1].Context[0].Integer) assert.Equal(t, "failed to index documents in 'an_index' (unavailable_shards_exception): ", entries[2].Message) assert.Equal(t, int64(2), entries[2].Context[0].Integer) + assert.Equal(t, "failed to index documents in 'an_index' (x_content_parse_exception): ", entries[3].Message) + assert.Equal(t, int64(2), entries[3].Context[0].Integer) } func TestAppenderRetryLimit(t *testing.T) { diff --git a/bulk_indexer.go b/bulk_indexer.go index c126a92..4b946ad 100644 --- a/bulk_indexer.go +++ b/bulk_indexer.go @@ -139,11 +139,12 @@ func init() { case "type": item.Error.Type = i.ReadString() case "reason": + reason := i.ReadString() // Match Elasticsearch field mapper field value: // failed to parse field [%s] of type [%s] in %s. Preview of field's value: '%s' // https://github.com/elastic/elasticsearch/blob/588eabe185ad319c0268a13480465966cef058cd/server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java#L234 item.Error.Reason, _, _ = strings.Cut( - i.ReadString(), ". Preview", + reason, ". Preview", ) default: i.Skip() @@ -155,8 +156,8 @@ func init() { } return true }) - // For unavailable_shards_exception, remove item.Error.Reason as it may contain sensitive request content. - if item.Error.Type == "unavailable_shards_exception" { + // For specific exceptions, remove item.Error.Reason as it may contain sensitive request content. + if item.Error.Type == "unavailable_shards_exception" || item.Error.Type == "x_content_parse_exception" { item.Error.Reason = "" }