Skip to content

Revise get aliases response #30536

Closed
Closed
@javanna

Description

@javanna

The get aliases API response is somewhat unique. As some other API, it mixes errors with valid aliases returned, which makes it quite hard to reason about. I would like us to review whether we want to make any change.

The usual response is something like the following:

curl localhost:9200/index*/_alias?pretty
{
  "index1" : {
    "aliases" : {
      "alias1" : { }
    }
  },
  "index2" : {
    "aliases" : { }
  },
  "index3" : {
    "aliases" : {
      "alias3" : { }
    }
  }
}

In case a requested index doesn't exist, an error gets returned (status 404):

curl localhost:9200/does_not_exist/_alias?pretty
{
  "error" : {
    "root_cause" : [
      {
        "type" : "index_not_found_exception",
        "reason" : "no such index",
        "resource.type" : "index_or_alias",
        "resource.id" : "does_not_exist",
        "index_uuid" : "_na_",
        "index" : "does_not_exist"
      }
    ],
    "type" : "index_not_found_exception",
    "reason" : "no such index",
    "resource.type" : "index_or_alias",
    "resource.id" : "does_not_exist",
    "index_uuid" : "_na_",
    "index" : "does_not_exist"
  },
  "status" : 404
}

When some requested aliases are not found though, the response becomes the following if no aliases are found:

curl 'localhost:9200/_alias/b*?pretty'
{
  "error" : "alias [b*] missing",
  "status" : 404
}

and becomes the following when some aliases are not found and some others are found:

curl 'localhost:9200/_alias/a*,b*?pretty'
{
  "error" : "alias [b*] missing",
  "status" : 404,
  "index1" : {
    "aliases" : {
      "alias1" : { }
    }
  },
  "index2" : {
    "aliases" : {
      "alias2" : { }
    }
  }
}

The error in the response above should probably be wrapped in another object, and the status returned is 404 although some aliases have been returned. Not sure whether that is intended. This was found as part of #28799 as this kind of responses is quite tricky to parse back when adding support for them to the high-level REST client. It is not clear whether we should throw an exception whenever 404 is returned, although in the last case some aliases were found and they would be lost if the client threw an exception. The other problem is that the structure of the "alias not found" error is not compliant to the usual errors that can be parsed back as an ElasticsearchException, which forces us to parse it back as a String. In fact on the server side it is not an exception, it is just how the response is rendered back at REST.

This seems like an example of API that can return "partial results", then the response should probably hold a failure object together with the aliases found?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions