Skip to content

Fix GetAliasResponse bug #1041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged

Fix GetAliasResponse bug #1041

merged 1 commit into from
Jul 25, 2025

Conversation

l-trotta
Copy link
Contributor

GetAliasesResponse is a special case because it can return both an exception and the actual response, in case 2 aliases, 1 present and 1 missing, are added to GetAliasesRequest:

{
  "error": "alias [test2] missing",
  "status": 404,
  "example-index": {
    "aliases": {
      "test": {}
    }
  }
}

The error deserializer doesn't recognize example-index (or any other custom field), and so a TransportException is thrown. This PR adds a default case to the error response deserializer so that any additional field is tentatively deserialized into the metadata map of ErrorCause.
So the json above would still the client throw an ElasticsearchException, since there's a 404 error, and the rest of the information would be found in metadata like so:

try{
    client.indices().getAlias(a -> a.name("test","test2"));
}
catch (ElasticsearchException e){
    Map<String, JsonData> metadata = e.error().metadata();
    JsonData index = metadata.get("example-index");
    Map aliases = index.to(Map.class);
    assertEquals("test", aliases.keySet().iterator().next());
}

Fixes #1033, fixes #900

@l-trotta l-trotta changed the title deserializing unknown key error response Fix GetAliasResponse bug Jul 24, 2025
@l-trotta l-trotta merged commit c3d8104 into main Jul 25, 2025
12 checks passed
@l-trotta l-trotta deleted the get-alias-response-fix branch July 25, 2025 06:53
l-trotta added a commit that referenced this pull request Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant