Skip to content

ShardFailure response must not require the 'primary' property#1878

Open
janhoy wants to merge 1 commit intoopensearch-project:mainfrom
janhoy:reproduce-shard_failure_parsing
Open

ShardFailure response must not require the 'primary' property#1878
janhoy wants to merge 1 commit intoopensearch-project:mainfrom
janhoy:reproduce-shard_failure_parsing

Conversation

@janhoy
Copy link
Contributor

@janhoy janhoy commented Feb 13, 2026

Description

When a request returns error with failed_shards, the current json parsing code requires that the shard object has a primary boolean property, but that is not always the case. The requirement was introduced in opensearch-project/opensearch-api-specification#981

Issues Resolved

Closes #1877

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Disclaimer: I have generated the reproduction test and the fix with AI assistant, and then manually reviewed and accepted the solution

Signed-off-by: Jan Høydahl <jan.git@cominvent.com>
.with(schema("_common", "StringifiedVersionNumber"), so -> so.withMappedType(Types.Primitive.Long))
.with(schema("_common", "Void"), so -> so.withMappedType(Types.Primitive.Void))

.with(schema("_common", "ShardFailure"), so -> so.withProperties(p -> p.with("primary", po -> po.withRequired(false))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This solution was chosen by Claude Code. I thought it might be possible to encode the non-null rule in the spec itself over in https://github.com/opensearch-project/opensearch-api-specification/ but I don't have any experience with that repo, so feel free to take this as a reproduction PR if you want to solve it in a different way.

### Fixed
- Fix formatting of the main method to run for various samples ([#1749](https://github.com/opensearch-project/opensearch-java/pull/1749))
- Fix NPE when null ObjectBuilder is accessed ([#1717](https://github.com/opensearch-project/opensearch-java/issues/1717))
- Fixed deserialization failure when OpenSearch returns shard failures without the `primary` field in error responses ([#XXXX](https://github.com/opensearch-project/opensearch-java/pull/XXXX))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
- Fixed deserialization failure when OpenSearch returns shard failures without the `primary` field in error responses ([#XXXX](https://github.com/opensearch-project/opensearch-java/pull/XXXX))
- Fixed deserialization failure when OpenSearch returns shard failures without the `primary` field in error responses ([#1878](https://github.com/opensearch-project/opensearch-java/pull/1878))

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 deserialization fails when OpenSearch omits the primary field in error responses

1 participant