diff --git a/client/elasticClient.go b/client/elasticClient.go index f8620f6e..64f7e30f 100644 --- a/client/elasticClient.go +++ b/client/elasticClient.go @@ -342,14 +342,11 @@ func (ec *elasticClient) getWriteIndex(alias string) (string, error) { IsWriteIndex bool `json:"is_write_index"` } `json:"aliases"` } - err = parseResponse(res, &indexData, elasticDefaultErrorResponseHandler) if err != nil { return "", err } - // Iterate over the map and find the write index - var writeIndex string for index, details := range indexData { if len(indexData) == 1 { return index, nil @@ -357,15 +354,12 @@ func (ec *elasticClient) getWriteIndex(alias string) (string, error) { for _, indexAlias := range details.Aliases { if indexAlias.IsWriteIndex { - writeIndex = index - break + return index, nil } } - if writeIndex != "" { - break - } } - return writeIndex, nil + + return alias, nil } // UpdateByQuery will update all the documents that match the provided query from the provided index diff --git a/client/testsData/response-get-alias-only-one-index.json b/client/testsData/response-get-alias-only-one-index.json index 2c28eb19..a56b11b8 100644 --- a/client/testsData/response-get-alias-only-one-index.json +++ b/client/testsData/response-get-alias-only-one-index.json @@ -4,4 +4,4 @@ "delegators" : { } } } -} \ No newline at end of file +} diff --git a/client/testsData/response-get-alias.json b/client/testsData/response-get-alias.json index a62f2670..2c29231e 100644 --- a/client/testsData/response-get-alias.json +++ b/client/testsData/response-get-alias.json @@ -27,4 +27,4 @@ } } } -} \ No newline at end of file +}