use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project elasticsearch by elastic.
the class RestAliasAction method doCatRequest.
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ? new GetAliasesRequest(request.param("alias")) : new GetAliasesRequest();
getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));
return channel -> client.admin().indices().getAliases(getAliasesRequest, new RestResponseListener<GetAliasesResponse>(channel) {
@Override
public RestResponse buildResponse(GetAliasesResponse response) throws Exception {
Table tab = buildTable(request, response);
return RestTable.buildResponse(tab, channel);
}
});
}
use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project elasticsearch by elastic.
the class RestGetAliasesAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name");
final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases);
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
getAliasesRequest.indices(indices);
getAliasesRequest.indicesOptions(IndicesOptions.fromRequest(request, getAliasesRequest.indicesOptions()));
getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));
return channel -> client.admin().indices().getAliases(getAliasesRequest, new RestBuilderListener<GetAliasesResponse>(channel) {
@Override
public RestResponse buildResponse(GetAliasesResponse response, XContentBuilder builder) throws Exception {
if (response.getAliases().isEmpty()) {
if (indices.length > 0) {
return new BytesRestResponse(OK, builder.startObject().endObject());
} else {
final String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases()));
builder.startObject();
{
builder.field("error", message);
builder.field("status", RestStatus.NOT_FOUND.getStatus());
}
builder.endObject();
return new BytesRestResponse(RestStatus.NOT_FOUND, builder);
}
} else {
builder.startObject();
{
for (final ObjectObjectCursor<String, List<AliasMetaData>> entry : response.getAliases()) {
builder.startObject(entry.key);
{
builder.startObject("aliases");
{
for (final AliasMetaData alias : entry.value) {
AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS);
}
}
builder.endObject();
}
builder.endObject();
}
}
builder.endObject();
return new BytesRestResponse(OK, builder);
}
}
});
}
use of org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project graylog2-server by Graylog2.
the class Indices method aliasTarget.
@Nullable
public String aliasTarget(String alias) throws TooManyAliasesException {
final IndicesAdminClient indicesAdminClient = c.admin().indices();
final GetAliasesRequest request = indicesAdminClient.prepareGetAliases(alias).request();
final GetAliasesResponse response = indicesAdminClient.getAliases(request).actionGet();
// The ES return value of this has an awkward format: The first key of the hash is the target index. Thanks.
final ImmutableOpenMap<String, List<AliasMetaData>> aliases = response.getAliases();
if (aliases.size() > 1) {
throw new TooManyAliasesException(Sets.newHashSet(aliases.keysIt()));
}
return aliases.isEmpty() ? null : aliases.keysIt().next();
}
Aggregations