Skip to content

Fix ShardFailure serializing wrong JSON keys (index/node/shard instead of _index/_node/_shard) - #2037

Open
gingeekrishna wants to merge 5 commits into
opensearch-project:mainfrom
gingeekrishna:fix/1799-shardfailure-shard-nullable
Open

Fix ShardFailure serializing wrong JSON keys (index/node/shard instead of _index/_node/_shard)#2037
gingeekrishna wants to merge 5 commits into
opensearch-project:mainfrom
gingeekrishna:fix/1799-shardfailure-shard-nullable

Conversation

@gingeekrishna

@gingeekrishna gingeekrishna commented Jul 5, 2026

Copy link
Copy Markdown

Description

Fixes #1799

Problem: When OpenSearch returns a ShardFailure, the Java client throws MissingRequiredPropertyException: Missing required property 'ShardFailure.shard'.

Root cause: This was originally diagnosed as shard being incorrectly required. That diagnosis was wrong. ReplicationResponse.ShardInfo.Failure on the server always writes the field — the real bug is a JSON key mismatch: the server writes _index, _shard, _node (underscore-prefixed), while _common___ShardFailure in opensearch-openapi.yaml and the generated ShardFailure.java used index, shard, node (no prefix). So the client looked up the wrong key: shard was never found under that name, producing the MissingRequiredPropertyException, and index/node were silently dropped since they aren't required.

This surfaced during review of the corresponding spec fix, opensearch-project/opensearch-api-specification#1194.

Fix:

  • java-codegen/opensearch-openapi.yaml — rename index/node/shard to _index/_node/_shard in _common___ShardFailure; keep _shard required (reverting an earlier, incorrect attempt to make it optional).
  • java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java — rename the three JSON keys used in serialization/deserialization to match. Java accessor/builder names are unchanged (index(), node(), shard()), consistent with existing underscore-prefixed fields elsewhere (e.g. Hit.index() for _index).

Changes

  • java-codegen/opensearch-openapi.yaml — rename index/node/shard to _index/_node/_shard; keep _shard required
  • java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java — rename JSON keys in serializeInternal/setupShardFailureDeserializer; shard stays a required, non-null int

@gingeekrishna
gingeekrishna requested a review from reta as a code owner July 5, 2026 07:36
Copilot AI review requested due to automatic review settings July 5, 2026 07:36

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.

gingeekrishna added a commit to gingeekrishna/opensearch-java that referenced this pull request Jul 5, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
@gingeekrishna
gingeekrishna force-pushed the fix/1799-shardfailure-shard-nullable branch from 2dfacc8 to a80639b Compare August 16, 2026 16:10
gingeekrishna added a commit to gingeekrishna/opensearch-java that referenced this pull request Aug 16, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please submit a change against https://github.com/opensearch-project/openSearch-api-specification, thank you

@gingeekrishna gingeekrishna Aug 17, 2026

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.

Submitted the spec fix upstream: opensearch-project/opensearch-api-specification#1194

@gingeekrishna

Copy link
Copy Markdown
Author

Submitted the spec fix upstream: opensearch-project/opensearch-api-specification#1194

gingeekrishna added a commit to gingeekrishna/opensearch-java that referenced this pull request Aug 30, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
@gingeekrishna
gingeekrishna force-pushed the fix/1799-shardfailure-shard-nullable branch from a80639b to 9768fe8 Compare August 30, 2026 06:25
@gingeekrishna gingeekrishna changed the title Fix ShardFailure.shard incorrectly required causing MissingRequiredPropertyException Fix ShardFailure serializing wrong JSON keys (index/node/shard instead of _index/_node/_shard) Aug 30, 2026
…rsing_exception

The _common___DerivedField schema in opensearch-openapi.yaml included a
required name property. This caused DerivedField.java to serialize a
name key into the JSON mapping body, but the OpenSearch API does not
accept name inside a derived field definition and returns:
  mapper_parsing_exception: unknown parameter [name] on mapper

In the API, the derived field's name is expressed as the map key in the
parent derived object, not as a property inside the field definition.

Remove name from the _common___DerivedField schema (both from
properties and required) and update the generated DerivedField.java
accordingly. The Java client no longer serializes name inside derived
field definitions.

Fixes opensearch-project#1937

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
…ailure

ShardFailure.shard was marked as required in the spec, so the generated
class threw MissingRequiredPropertyException when OpenSearch returned a
ShardFailure without the shard field — masking the real failure.

Per the OpenSearch API, shard is an optional integer in ShardFailure
(the primary failure reason is always present; the shard number may
be absent for certain failure types).

Remove shard from the required list in _common___ShardFailure and
update the generated ShardFailure.java to use @nullable Integer with
proper null guards in serialization, hashCode, and equals.

Fixes opensearch-project#1799

Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
The previous commit made shard optional, on the assumption the server
sometimes omits it. Per review on the corresponding spec change
(opensearch-project/opensearch-api-specification#1194), that was
wrong: ReplicationResponse.ShardInfo.Failure on the server always
writes the field. The real bug was a JSON key mismatch: the server
writes _index, _shard, _node (underscore-prefixed), but the spec and
this client used index, shard, node, so deserialization looked up the
wrong key and threw MissingRequiredPropertyException on _shard/shard,
or silently dropped _index/_node.

Revert shard to a required, non-null int, and rename the three JSON
keys (index/node/shard -> _index/_node/_shard) in both
opensearch-openapi.yaml and the generated ShardFailure.java. Java
accessor/builder names are unchanged (index(), node(), shard()) per
the existing convention for underscore-prefixed API fields (see
Hit.index() for _index).

Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
@gingeekrishna
gingeekrishna force-pushed the fix/1799-shardfailure-shard-nullable branch from b0231e4 to d19fd14 Compare September 4, 2026 05:54
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.

[BUG] ShardFailure hides real failure if ApiTypeHelper assertion fails

3 participants