Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Apr 9, 2024
1 parent d37c354 commit 83bd2ee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
12 changes: 3 additions & 9 deletions client/elasticClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,24 @@ 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
}

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
Expand Down
2 changes: 1 addition & 1 deletion client/testsData/response-get-alias-only-one-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"delegators" : { }
}
}
}
}
2 changes: 1 addition & 1 deletion client/testsData/response-get-alias.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
}
}
}
}
}

0 comments on commit 83bd2ee

Please sign in to comment.