@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name");
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases);
getAliasesRequest.indices(indices);
getAliasesRequest.indicesOptions(IndicesOptions.fromRequest(request, getAliasesRequest.indicesOptions()));
getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));
client.admin().indices().getAliases(getAliasesRequest, new RestBuilderListener<GetAliasesResponse>(channel) {
@Override
public RestResponse buildResponse(GetAliasesResponse response, XContentBuilder builder) throws Exception {
// empty body, if indices were specified but no aliases were
if (indices.length > 0 && response.getAliases().isEmpty()) {
return new BytesRestResponse(OK, builder.startObject().endObject());
} else if (response.getAliases().isEmpty()) {
String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases()));
builder.startObject()
.field("error", message)
.field("status", RestStatus.NOT_FOUND.getStatus())
.endObject();
return new BytesRestResponse(RestStatus.NOT_FOUND, builder);