Skip to content
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

Failed to decode response when requesting aliases for indices and some do not exist #900

Open
kved96 opened this issue Oct 24, 2024 · 3 comments
Labels
Area: Generator Category: Bug Something isn't working

Comments

@kved96
Copy link

kved96 commented Oct 24, 2024

Java API client version

8.14.3

Java version

17

Elasticsearch Version

8.14.3

Problem description

Running a request for getting indices from aliases throws an UnexpectedJsonEventException when some aliases do not exist, but some do.

co.elastic.clients.transport.TransportException: node: <node name> [es/indices.get_alias] Failed to decode error response, check exception cause for additional details

Exception cause:

co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'START_OBJECT' instead of 'KEY_NAME'

To reproduce, create an index test_index with an alias test and an index test_index2 without an alias, then using the java client run:

esClient.indices()
                .getAlias(a -> a.name(List.of("test", "test2"))
                        .allowNoIndices(true)
                        .ignoreUnavailable(true)
                        .expandWildcards(ExpandWildcard.Open))
                .result()

The intended behavior would be to throw the following exception:

co.elastic.clients.elasticsearch._types.ElasticsearchException

ErrorResponse: {"error":{"type":"http_status_404","reason":"alias [test] missing"},"status":404}

Running the same request via curl produces the following:

$ curl https://localhost:9200/_alias/test,test2?pretty
{
  "error" : "alias [test2] missing",
  "status" : 404,
  "test_index" : {
    "aliases" : {
      "test" : { }
    }
  }
}
@l-trotta
Copy link
Contributor

Hello, thanks for reporting this! This is a limitation of the java client at the moment, we don't map specific exception responses like this one as we just have the common ErrorResponse type, but hypothetically it shouldn't be too hard to make it accept additional fields, to support cases like this one - I'll see what we can do.

@l-trotta l-trotta added Area: Generator Category: Bug Something isn't working labels Oct 24, 2024
@kved96
Copy link
Author

kved96 commented Oct 24, 2024

Hey @l-trotta thanks for the response! It's interesting because when I just query for an alias that doesn't exist, it returns the correct 404 response with the correct message. This error only seems to happen when querying for an alias that doesn't exist as well as an alias that does exist, which is telling me that the error is different in both cases and the java client has handling for the former, but not the latter, is this correct?

@l-trotta
Copy link
Contributor

@kved96 exactly! The error class doesn't recognize fields other than error and status, so when it also includes the correct result it fails to deserialize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Generator Category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants