Skip to content

Add doc counts to BulkIndexerResponseStat - #326

Merged
marclop merged 2 commits into
mainfrom
indexed-per-index
Oct 15, 2026
Merged

marclop merged 2 commits into
mainfrom
indexed-per-index

Conversation

@marclop

@marclop marclop commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

The bulk response decoder reads _index for every item, but it only keeps it for failed documents, which end up in FailedDocs with their Index. Successful documents just bump Indexed, so a caller has no way to know which indices they were written to. We would like to expose the destination index as an opt-in metric attribute.

This PR adds BulkIndexerResponseStat.IndexStats, mapping a destination index to a BulkIndexerIndexStat holding Indexed / Failed counts. It's opt-in with a new BulkIndexerConfig.PopulateIndexStats, so existing users don't incur the cost unless they're intested in the stat.

When it's on, it costs one map allocation per flush, which grows with the number of distinct indices in a bulk request. Since _index is already part of the response, it doesn't change the size either way.

The Indexed count is what you'd expect, and Failed is filled in at the end of Flush from the final FailedDocs instead of in the decoder, so we avoid counting retries or document-level retries as Failed.

@marclop
marclop requested a review from a team as a code owner October 13, 2026 00:01
@elastic-observability-automation elastic-observability-automation Bot added the safe-to-test Automated label for running bench-diff on forked PRs label Oct 13, 2026
The bulk response decoder reads `_index` for every item, but it only
keeps it for failed documents, which end up in FailedDocs with their
Index. Successful documents just bump Indexed, so a caller has no way to
know which indices they were written to. We would like to expose the
destination index as an opt-in metric attribute.

This PR adds `BulkIndexerResponseStat.IndexStats`, mapping a destination
index to a `BulkIndexerIndexStat` holding Indexed / Failed counts. It's
opt-in with a new `BulkIndexerConfig.PopulateIndexStats`, so existing
users don't incur the cost unless they're intested in the stat.

When it's on, it costs one map allocation per flush, which grows with
the number of distinct indices in a bulk request. Since `_index` is
already part of the response, it doesn't change the size either way.

The Indexed count is what you'd expect, so it includes the documents
indexed to the failure store like the response-level one does, and
Failed is filled in at the end of Flush from the final FailedDocs
instead of in the decoder, so we avoid counting retries or
document-level retries as Failed.

A document redirected to the failure store returns a 201 with the `.fs-`
index in `_index`, so it would be indistinguishable from any other
success. To tell them apart, each index also carries `FailureStoreDocs`
with the used / failed / not_enabled counts. They're counted once the
whole item is decoded, since the response doesn't guarantee that `_index`
comes before `failure_store`.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
@marclop marclop changed the title Add document counts to BulkIndexerResponseStat Add doc counts to BulkIndexerResponseStat Oct 14, 2026
@marclop
marclop enabled auto-merge (squash) October 14, 2026 04:47

@lahsivjar lahsivjar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@marclop
marclop merged commit 14196b1 into main Oct 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Automated label for running bench-diff on forked PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants