Skip to content

[BUG] ShardFailure deserialization fails when OpenSearch omits the primary field in error responses #1877

Description

@janhoy

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?

  1. Execute a search query that triggers a shard failure (e.g., malformed query, index with shard issues)
  2. OpenSearch returns an error response containing failed_shards in the error metadata
  3. The Java client attempts to deserialize the ShardFailure objects
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv3.7.0Issues and PRs related to version v3.7.0

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions