Skip to content

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
Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant