Skip to content

fix(_common): rename ShardFailure fields to match server response - #1194

Open
gingeekrishna wants to merge 3 commits into
opensearch-project:mainfrom
gingeekrishna:fix/shard-failure-shard-optional
Open

fix(_common): rename ShardFailure fields to match server response#1194
gingeekrishna wants to merge 3 commits into
opensearch-project:mainfrom
gingeekrishna:fix/shard-failure-shard-optional

Conversation

@gingeekrishna

@gingeekrishna gingeekrishna commented Aug 17, 2026

Copy link
Copy Markdown

Description

Rename the ShardFailure schema properties in spec/schemas/_common.yaml from index/node/shard to _index/_node/_shard to match what ReplicationResponse.ShardInfo.Failure on the OpenSearch server actually serializes (underscore-prefixed keys for _index, _shard, _node; no prefix for reason, status, primary).

An earlier version of this PR instead removed shard from required, on the assumption that the server sometimes omits it. As pointed out in review, the server always writes the field — the real problem was the name mismatch, so clients were looking up shard and finding nothing under that key while the actual value sat under _shard. This restores _shard as required and renames all three affected properties.

Related Issues

Reported via opensearch-java#1799 and the corresponding fix opensearch-java#2037.

Checklist

  • Ran YAML validation locally
  • _shard restored as required, matching server behavior; _index/_node/_shard now match the server's actual JSON keys

Signed-off-by: Radha Krishnan P gingeekrishna@gmail.com

OpenSearch may omit the shard field in ShardFailure responses for
certain failure types (e.g. index-level failures where no specific
shard is implicated). The field was incorrectly listed as required,
causing MissingRequiredPropertyException in the Java client when
deserializing responses from opensearch-project/opensearch-java#1799.

Remove shard from the required list; it remains defined as an integer
property so it is still serialized/deserialized when present.

Signed-off-by: Radha Krishnan P <gingeekrishna@gmail.com>
Copilot AI lite review requested due to automatic review settings August 17, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread spec/schemas/_common.yaml
required:
- primary
- reason
- shard

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.

I looked at the server code, sorry I don't think removing shard from required is the right fix here.

ShardFailure schema is used inside ShardInfo.failures (line 315), which corresponds to ReplicationResponse.ShardInfo.Failure on the server side. that class always writes the shard field, it never omits it:

builder.field(_SHARD, shardId.id());
builder.field(_INDEX, shardId.getIndexName());
builder.field(_NODE, nodeId);

real problem is a field name mismatch. server writes _shard, _index, _node (with underscores), but this spec defines them as shard, index, node (without underscores). so the Java client looks for shard in the JSON, doesn't find it because the actual key is _shard, and throws MissingRequiredPropertyException.

making shard optional just hides this, client will silently get null instead of the actual shard ID. fix should be correcting the property names to match what the server actually returns.

Can you check the actual JSON response from the server that triggered the original issue? I'd expect the fields are there but named _shard, _index, _node.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thanks for checking the server code. You're right, removing shard from required just masked the real bug. Fixed in 646c39d: renamed index/node/shard to _index/_node/_shard to match what ReplicationResponse.ShardInfo.Failure actually writes, and restored _shard as required since the server always includes it. Also updated the PR title/description accordingly.

ReplicationResponse.ShardInfo.Failure on the server always writes the
shard field, so making it optional just masked a MissingRequiredPropertyException
instead of fixing it. The real issue is a name mismatch: the server
writes _index, _shard, _node (underscore-prefixed) while this schema
defined index, shard, node without the prefix, so clients looked up
the wrong key and got null/missing errors.

Rename the properties to _index, _shard, _node to match what the
server actually serializes, and restore shard (as _shard) as required
since the server always includes it.

Addresses review comment from @iprithv on opensearch-project#1194.

Signed-off-by: Radha Krishnan P <gingeekrishna@gmail.com>
@gingeekrishna gingeekrishna changed the title fix(_common): make ShardFailure.shard optional fix(_common): rename ShardFailure fields to match server response Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants