What is the bug?
This is a regression in version 3.5.0, introduced by this commit, after fetching latest api-spec and doing code-gen.
In opensearch-java v3.4.0 this worked, but from v3.5.0, the client throws a MissingRequiredPropertyException when attempting to deserialize error responses that contain shard failures, since primary field is now required in the updated api-spec. This occurs during search requests when OpenSearch returns shard-level failures in the error response.
Error:
org.opensearch.client.util.MissingRequiredPropertyException: Missing required property 'ShardFailure.primary'
How can one reproduce the bug?
- Execute a search query that triggers a shard failure (e.g., malformed query, index with shard issues)
- OpenSearch returns an error response containing
failed_shards in the error metadata
- The Java client attempts to deserialize the
ShardFailure objects
- Deserialization fails because the
primary field is marked as required but OpenSearch omits it
Example error response structure:
{
"error": {
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"failed_shards": [
{
"shard": 0,
"index": "my-index",
"node": "node-id",
"reason": {
"type": "query_shard_exception",
"reason": "Parse failure"
}
}
]
}
}
Note: The primary field is missing from the failed_shards objects.
What is the expected behavior?
The client should successfully deserialize error responses containing shard failures, regardless of whether the primary field is present or not. The primary field should be treated as optional since OpenSearch doesn't consistently include it in all error responses.
What is your host/environment?
- OpenSearch Java Client version: 3.5
Do you have any screenshots?
No
Do you have any additional context?
Root Cause:
The ShardFailure class (generated from the OpenAPI spec) marks the primary field as required and uses a primitive boolean type, which cannot be null. However, OpenSearch's actual error responses often omit this field, causing a mismatch between the spec and real-world behavior.
Affected Code:
- java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java
Proposed Fix:
- 3.x: Make the
primary attribute not required
- 4.x: Introduce
ShardSearchFailure schema class distinct from ShardFailure
What is the bug?
This is a regression in version 3.5.0, introduced by this commit, after fetching latest api-spec and doing code-gen.
In opensearch-java v3.4.0 this worked, but from v3.5.0, the client throws a
MissingRequiredPropertyExceptionwhen attempting to deserialize error responses that contain shard failures, sinceprimaryfield is now required in the updated api-spec. This occurs during search requests when OpenSearch returns shard-level failures in the error response.Error:
org.opensearch.client.util.MissingRequiredPropertyException: Missing required property 'ShardFailure.primary'
How can one reproduce the bug?
failed_shardsin the error metadataShardFailureobjectsprimaryfield is marked as required but OpenSearch omits itExample error response structure:
{ "error": { "type": "search_phase_execution_exception", "reason": "all shards failed", "failed_shards": [ { "shard": 0, "index": "my-index", "node": "node-id", "reason": { "type": "query_shard_exception", "reason": "Parse failure" } } ] } }Note: The
primaryfield is missing from the failed_shards objects.What is the expected behavior?
The client should successfully deserialize error responses containing shard failures, regardless of whether the primary field is present or not. The primary field should be treated as optional since OpenSearch doesn't consistently include it in all error responses.
What is your host/environment?
Do you have any screenshots?
No
Do you have any additional context?
Root Cause:
The ShardFailure class (generated from the OpenAPI spec) marks the primary field as required and uses a primitive boolean type, which cannot be null. However, OpenSearch's actual error responses often omit this field, causing a mismatch between the spec and real-world behavior.
Affected Code:
Proposed Fix:
primaryattribute not requiredShardSearchFailureschema class distinct fromShardFailure