Skip to content

fix(search): report rejected documents when indexing to OpenSearch#3142

Open
dschmidt wants to merge 3 commits into
mainfrom
fix/opensearch-bulk-item-errors
Open

fix(search): report rejected documents when indexing to OpenSearch#3142
dschmidt wants to merge 3 commits into
mainfrom
fix/opensearch-bulk-item-errors

Conversation

@dschmidt

@dschmidt dschmidt commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Batch.Push discarded the bulk response. The bulk API answers 200 even when it rejects individual items, so a rejected document went missing from the index without a trace. Purge already checks resp.Failures for DeleteByQuery, this does the same for Bulk.

While at it: those DeleteByQuery failures were printed as byte arrays, resp.Failures is a []json.RawMessage.

This only makes the loss visible, it does not prevent it. The event is acked either way and nothing retries.

@dschmidt
dschmidt force-pushed the fix/opensearch-bulk-item-errors branch from ec1451b to 28e148c Compare July 15, 2026 22:59
@codacy-production

codacy-production Bot commented Jul 15, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 7 duplication

Metric Results
Complexity 0
Duplication 7

View in Codacy

🟢 Coverage 76.47% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation +0.01% coverage variation (-1.00%)
Diff coverage 76.47% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (85e63ca) 82473 19129 23.19%
Head commit (87dd68a) 82486 (+13) 19138 (+9) 23.20% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3142) 17 13 76.47%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@dschmidt
dschmidt force-pushed the fix/opensearch-bulk-item-errors branch from 140495b to 26a44bb Compare July 15, 2026 23:11
@dschmidt
dschmidt force-pushed the fix/opensearch-bulk-item-errors branch from 26a44bb to 9beb00a Compare July 15, 2026 23:20
return fmt.Errorf("failed to delete by query: %w", err)
case len(resp.Failures) != 0:
return fmt.Errorf("failed to delete by query, failures: %v", resp.Failures)
return fmt.Errorf("failed to delete by query, failures: %s", resp.Failures)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resp.Failures is a []json.RawMessage, and json.RawMessage is a []byte without a String() method, so %v rendered the failures as byte arrays:

[[123 34 105 110 100 101 120 34 58 34 111 112 101 110 ...]]

%s prints what the API actually returned:

[{"index":"opencloud-demo-dbq","id":"1$1!3","cause":{"type":"cluster_block_exception","reason":"index [opencloud-demo-dbq] blocked by: [FORBIDDEN/8/index write (api)];"},"status":403}]

Comment thread services/search/pkg/opensearch/batch.go Outdated
@dschmidt
dschmidt marked this pull request as ready for review July 15, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant