[BUG] Wrong request path computed in AliasGetReq
when no indices are specified
#617
Labels
bug
Something isn't working
AliasGetReq
when no indices are specified
#617
What is the bug?
OpenSearch supports two kind of routes to get an alias:
GET /_alias/alias1
andGET /alias1
. To interact with these routes, theopensearchapi
package provides theAliasGetReq
request. The problem arises when no indices are specified: in this case, theGetRequest()
function computes a request path that is equal to//_alias/alias1
. When passed tohttp.NewRequest()
, the double slash at the beginning makes_alias
be set as host andalias1
as path, and when the host is replaced insetReqURL()
, the ending request URL ishttp://localhost:9200/alias1
instead of the expectedhttp://localhost:9200/_alias/alias1
. While the response for the success case is coincidentally compatible, the behavior is different if more than one alias is specified and some do not exist. In that case, the first endpoint returns a structured error while the second returns the information about the existing aliases along with an error message and a status field. This makes it difficult to handle errors as you expect to receive them in a certain format when in reality this is not the case.How can one reproduce the bug?
It it enough to write this code:
What is the expected behavior?
The request returned by
AliasGetReq.GetRequest()
should have/_alias/alias1
set as path when no indices are specified.Do you have any additional context?
It used to work fine before version
3.0
. The commit that introduced the bugged code is 9d56cba. I'm open to submit a PR to fix the issue once it's triaged.The text was updated successfully, but these errors were encountered: