Remove GET `_aliases` api in favour for GET `_alias` api
Currently there are two get aliases apis that both have the same functionality, but have a different response structure. The reason for having 2 apis is historic. The GET _alias api was added in 0.90.x and is more efficient since it only sends the needed alias data from the cluster state between the master node and the node that received the request. In the GET _aliases api the complete cluster state is send to the node that received the request and then the right information is filtered out and send back to the client. The GET _aliases api should be removed in favour for the alias api Closes to #4539
This commit is contained in:
parent
8d4be46e59
commit
aa548f5148
|
@ -227,7 +227,7 @@ Possible options:
|
|||
`alias`::
|
||||
The name of alias to return in the response. Like the index
|
||||
option, this option supports wildcards and the option the specify
|
||||
multiple alias names separated by a comma. This is a required option.
|
||||
multiple alias names separated by a comma.
|
||||
|
||||
`ignore_unavailable`::
|
||||
What to do is an specified index name doesn't
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"methods": ["HEAD"],
|
||||
"url": {
|
||||
"path": "/_alias/{name}",
|
||||
"paths": ["/_alias/{name}", "/{index}/_alias/{name}"],
|
||||
"paths": ["/_alias/{name}", "/{index}/_alias/{name}", "/{index}/_alias"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
|
@ -12,7 +12,6 @@
|
|||
},
|
||||
"name": {
|
||||
"type" : "list",
|
||||
"required" : true,
|
||||
"description" : "A comma-separated list of alias names to return"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"methods": ["GET"],
|
||||
"url": {
|
||||
"path": "/_alias/{name}",
|
||||
"paths": ["/_alias/{name}", "/{index}/_alias/{name}"],
|
||||
"paths": ["/_alias/{name}", "/{index}/_alias/{name}", "/{index}/_alias"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
|
@ -12,7 +12,6 @@
|
|||
},
|
||||
"name": {
|
||||
"type" : "list",
|
||||
"required" : true,
|
||||
"description" : "A comma-separated list of alias names to return"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"indices.get_aliases": {
|
||||
"documentation": "http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/",
|
||||
"methods": ["GET"],
|
||||
"url": {
|
||||
"path": "/_aliases",
|
||||
"paths": ["/_aliases", "/{index}/_aliases"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
"description" : "A comma-separated list of index names to filter aliases"
|
||||
}
|
||||
},
|
||||
"params": {
|
||||
"timeout": {
|
||||
"type" : "time",
|
||||
"description" : "Explicit operation timeout"
|
||||
}
|
||||
}
|
||||
},
|
||||
"body": null
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
- is_true: ''
|
||||
|
||||
- do:
|
||||
indices.get_aliases:
|
||||
indices.get_alias:
|
||||
index: test_index
|
||||
|
||||
- match: {test_index.aliases.test_alias: {'index_routing': 'routing_value', 'search_routing': 'routing_value'}}
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.elasticsearch.rest.action.admin.cluster.snapshots.restore.RestRestore
|
|||
import org.elasticsearch.rest.action.admin.cluster.state.RestClusterStateAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.stats.RestClusterStatsAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.tasks.RestPendingClusterTasksAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.RestGetIndicesAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.RestIndicesAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.delete.RestIndexDeleteAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.get.RestGetAliasesAction;
|
||||
|
@ -147,7 +146,6 @@ public class RestActionModule extends AbstractModule {
|
|||
bind(RestIndicesStatsAction.class).asEagerSingleton();
|
||||
bind(RestIndicesStatusAction.class).asEagerSingleton();
|
||||
bind(RestIndicesSegmentsAction.class).asEagerSingleton();
|
||||
bind(RestGetIndicesAliasesAction.class).asEagerSingleton();
|
||||
bind(RestGetAliasesAction.class).asEagerSingleton();
|
||||
bind(RestAliasesExistAction.class).asEagerSingleton();
|
||||
bind(RestIndexDeleteAliasesAction.class).asEagerSingleton();
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest.action.admin.indices.alias;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RestGetIndicesAliasesAction extends BaseRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestGetIndicesAliasesAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(GET, "/_aliases", this);
|
||||
controller.registerHandler(GET, "/{index}/_aliases", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
|
||||
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
|
||||
.filterRoutingTable(true)
|
||||
.filterNodes(true)
|
||||
.filteredIndices(indices);
|
||||
|
||||
clusterStateRequest.listenerThreaded(false);
|
||||
|
||||
client.admin().cluster().state(clusterStateRequest, new ActionListener<ClusterStateResponse>() {
|
||||
@Override
|
||||
public void onResponse(ClusterStateResponse response) {
|
||||
try {
|
||||
MetaData metaData = response.getState().metaData();
|
||||
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
||||
builder.startObject();
|
||||
|
||||
for (IndexMetaData indexMetaData : metaData) {
|
||||
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
|
||||
|
||||
builder.startObject("aliases");
|
||||
for (ObjectCursor<AliasMetaData> cursor : indexMetaData.aliases().values()) {
|
||||
AliasMetaData.Builder.toXContent(cursor.value, builder, ToXContent.EMPTY_PARAMS);
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
|
||||
channel.sendResponse(new XContentRestResponse(request, OK, builder));
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new XContentThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@ public class RestGetAliasesAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
controller.registerHandler(GET, "/_alias/{name}", this);
|
||||
controller.registerHandler(GET, "/{index}/_alias/{name}", this);
|
||||
controller.registerHandler(GET, "/{index}/_alias", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -43,6 +43,7 @@ public class RestAliasesExistAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
controller.registerHandler(HEAD, "/_alias/{name}", this);
|
||||
controller.registerHandler(HEAD, "/{index}/_alias/{name}", this);
|
||||
controller.registerHandler(HEAD, "/{index}/_alias", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue