Added indices aliases exists api.
Added indices aliases exists api that allows to check to existence of an index alias. This api redirects to the master to check for the existence of one or multiple index aliases. Possible options: * `index` - The index name to check index aliases for. Partially names are supported via wildcards, also multiple index names can be specified separated with a comma. Also the alias name for an index can be used. * `alias` - The name of alias to check the existence for. 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. * `ignore_indices` - What to do is an specified index name doesn't exist. If set to `missing` then those indices are ignored. The rest head endpoint is: `/{index}/_alias/{alias}` Examples: Check existence for any aliases with the name 2013 in any index: ``` curl -XHEAD 'localhost:9200/_alias/2013 ``` Check existence for any aliases that start with 2013_01 in any index ``` curl -XHEAD 'localhost:9200/_alias/2013_01* ``` Check existence for any aliases in the users index. ``` curl -XHEAD 'localhost:9200/users/_alias/* ``` Closes #3100
This commit is contained in:
parent
b4d75a50bf
commit
8b95c5fab8
|
@ -42,6 +42,8 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
|
|||
import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.TransportIndicesExistsAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.TransportIndicesGetAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction;
|
||||
|
@ -204,6 +206,7 @@ public class ActionModule extends AbstractModule {
|
|||
registerAction(PutWarmerAction.INSTANCE, TransportPutWarmerAction.class);
|
||||
registerAction(DeleteWarmerAction.INSTANCE, TransportDeleteWarmerAction.class);
|
||||
registerAction(IndicesGetAliasesAction.INSTANCE, TransportIndicesGetAliasesAction.class);
|
||||
registerAction(IndicesExistsAliasesAction.INSTANCE, TransportIndicesExistsAliasesAction.class);
|
||||
|
||||
registerAction(IndexAction.INSTANCE, TransportIndexAction.class);
|
||||
registerAction(GetAction.INSTANCE, TransportGetAction.class);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.action.admin.indices.alias.exists;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.IndicesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequest;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class IndicesExistsAliasesAction extends IndicesAction<IndicesGetAliasesRequest, IndicesExistsAliasesResponse, IndicesExistsAliasesRequestBuilder> {
|
||||
|
||||
public static final IndicesExistsAliasesAction INSTANCE = new IndicesExistsAliasesAction();
|
||||
public static final String NAME = "indices/exists/aliases";
|
||||
|
||||
private IndicesExistsAliasesAction() {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicesExistsAliasesRequestBuilder newRequestBuilder(IndicesAdminClient client) {
|
||||
return new IndicesExistsAliasesRequestBuilder(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicesExistsAliasesResponse newResponse() {
|
||||
return new IndicesExistsAliasesResponse();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.action.admin.indices.alias.exists;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.BaseIndicesAliasesRequestBuilder;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class IndicesExistsAliasesRequestBuilder extends BaseIndicesAliasesRequestBuilder<IndicesExistsAliasesResponse, IndicesExistsAliasesRequestBuilder> {
|
||||
|
||||
public IndicesExistsAliasesRequestBuilder(IndicesAdminClient client, String... aliases) {
|
||||
super(client, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<IndicesExistsAliasesResponse> listener) {
|
||||
((IndicesAdminClient) client).existsAliases(request, listener);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.action.admin.indices.alias.exists;
|
||||
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class IndicesExistsAliasesResponse extends ActionResponse {
|
||||
|
||||
private boolean exists;
|
||||
|
||||
public IndicesExistsAliasesResponse(boolean exists) {
|
||||
this.exists = exists;
|
||||
}
|
||||
|
||||
IndicesExistsAliasesResponse() {
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
public boolean isExists() {
|
||||
return exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
exists = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeBoolean(exists);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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.action.admin.indices.alias.exists;
|
||||
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequest;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TransportIndicesExistsAliasesAction extends TransportMasterNodeOperationAction<IndicesGetAliasesRequest, IndicesExistsAliasesResponse> {
|
||||
|
||||
@Inject
|
||||
public TransportIndicesExistsAliasesAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) {
|
||||
super(settings, transportService, clusterService, threadPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String transportAction() {
|
||||
return IndicesExistsAliasesAction.NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String executor() {
|
||||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndicesGetAliasesRequest newRequest() {
|
||||
return new IndicesGetAliasesRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndicesExistsAliasesResponse newResponse() {
|
||||
return new IndicesExistsAliasesResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IndicesExistsAliasesResponse masterOperation(IndicesGetAliasesRequest request, ClusterState state) throws ElasticSearchException {
|
||||
String[] concreteIndices = state.metaData().concreteIndices(request.indices(), request.ignoreIndices(), true);
|
||||
request.indices(concreteIndices);
|
||||
|
||||
boolean result = state.metaData().hasAliases(request.aliases(), request.indices());
|
||||
return new IndicesExistsAliasesResponse(result);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.action.admin.indices.alias.get;
|
||||
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
public abstract class BaseIndicesAliasesRequestBuilder<Response extends ActionResponse, Builder extends BaseIndicesAliasesRequestBuilder<Response, Builder>> extends MasterNodeOperationRequestBuilder<IndicesGetAliasesRequest, Response, Builder> {
|
||||
|
||||
public BaseIndicesAliasesRequestBuilder(IndicesAdminClient client, String... aliases) {
|
||||
super((InternalIndicesAdminClient) client, new IndicesGetAliasesRequest(aliases));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder setAliases(String... aliases) {
|
||||
request.aliases(aliases);
|
||||
return (Builder) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder addAliases(String... aliases) {
|
||||
request.aliases(ObjectArrays.concat(request.aliases(), aliases, String.class));
|
||||
return (Builder) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder setIndices(String... indices) {
|
||||
request.indices(indices);
|
||||
return (Builder) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder addIndices(String... indices) {
|
||||
request.indices(ObjectArrays.concat(request.indices(), indices, String.class));
|
||||
return (Builder) this;
|
||||
}
|
||||
|
||||
}
|
|
@ -46,7 +46,7 @@ public class IndicesGetAliasesRequest extends MasterNodeOperationRequest<Indices
|
|||
this.aliases = new String[]{alias};
|
||||
}
|
||||
|
||||
IndicesGetAliasesRequest() {
|
||||
public IndicesGetAliasesRequest() {
|
||||
}
|
||||
|
||||
public IndicesGetAliasesRequest indices(String... indices) {
|
||||
|
|
|
@ -19,38 +19,15 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.alias.get;
|
||||
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class IndicesGetAliasesRequestBuilder extends MasterNodeOperationRequestBuilder<IndicesGetAliasesRequest, IndicesGetAliasesResponse, IndicesGetAliasesRequestBuilder> {
|
||||
public class IndicesGetAliasesRequestBuilder extends BaseIndicesAliasesRequestBuilder<IndicesGetAliasesResponse, IndicesGetAliasesRequestBuilder> {
|
||||
|
||||
public IndicesGetAliasesRequestBuilder(IndicesAdminClient client, String... aliases) {
|
||||
super((InternalIndicesAdminClient)client, new IndicesGetAliasesRequest(aliases));
|
||||
}
|
||||
|
||||
public IndicesGetAliasesRequestBuilder setAliases(String... aliases) {
|
||||
request.aliases(aliases);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndicesGetAliasesRequestBuilder addAliases(String... aliases) {
|
||||
request.aliases(ObjectArrays.concat(request.aliases(), aliases, String.class));
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndicesGetAliasesRequestBuilder setIndices(String... indices) {
|
||||
request.indices(indices);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndicesGetAliasesRequestBuilder addIndices(String... indices) {
|
||||
request.indices(ObjectArrays.concat(request.indices(), indices, String.class));
|
||||
return this;
|
||||
super(client, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.elasticsearch.action.admin.indices.IndicesAction;
|
|||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesResponse;
|
||||
|
@ -480,14 +482,14 @@ public interface IndicesAdminClient {
|
|||
IndicesAliasesRequestBuilder prepareAliases();
|
||||
|
||||
/**
|
||||
* Get specific index aliases.
|
||||
* Get specific index aliases that exists in particular indices and / or by name.
|
||||
*
|
||||
* @param request The result future
|
||||
*/
|
||||
ActionFuture<IndicesGetAliasesResponse> getAliases(IndicesGetAliasesRequest request);
|
||||
|
||||
/**
|
||||
* Get specific index aliases.
|
||||
* Get specific index aliases that exists in particular indices and / or by name.
|
||||
*
|
||||
* @param request The index aliases request
|
||||
* @param listener A listener to be notified with a result
|
||||
|
@ -495,10 +497,30 @@ public interface IndicesAdminClient {
|
|||
void getAliases(IndicesGetAliasesRequest request, ActionListener<IndicesGetAliasesResponse> listener);
|
||||
|
||||
/**
|
||||
* Adds specific index aliases.
|
||||
* Get specific index aliases that exists in particular indices and / or by name.
|
||||
*/
|
||||
IndicesGetAliasesRequestBuilder prepareGetAliases(String... aliases);
|
||||
|
||||
/**
|
||||
* Allows to check to existence of aliases from indices.
|
||||
*/
|
||||
IndicesExistsAliasesRequestBuilder prepareExistsAliases(String... aliases);
|
||||
|
||||
/**
|
||||
* Check to existence of index aliases.
|
||||
*
|
||||
* @param request The result future
|
||||
*/
|
||||
ActionFuture<IndicesExistsAliasesResponse> existsAliases(IndicesGetAliasesRequest request);
|
||||
|
||||
/**
|
||||
* Check the existence of specified index aliases.
|
||||
*
|
||||
* @param request The index aliases request
|
||||
* @param listener A listener to be notified with a result
|
||||
*/
|
||||
void existsAliases(IndicesGetAliasesRequest request, ActionListener<IndicesExistsAliasesResponse> listener);
|
||||
|
||||
/**
|
||||
* Clear indices cache.
|
||||
*
|
||||
|
|
|
@ -25,6 +25,9 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
|
|||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequestBuilder;
|
||||
|
@ -199,6 +202,21 @@ public abstract class AbstractIndicesAdminClient implements InternalIndicesAdmin
|
|||
return execute(ClearIndicesCacheAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void existsAliases(IndicesGetAliasesRequest request, ActionListener<IndicesExistsAliasesResponse> listener) {
|
||||
execute(IndicesExistsAliasesAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<IndicesExistsAliasesResponse> existsAliases(IndicesGetAliasesRequest request) {
|
||||
return execute(IndicesExistsAliasesAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicesExistsAliasesRequestBuilder prepareExistsAliases(String... aliases) {
|
||||
return new IndicesExistsAliasesRequestBuilder(this, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCache(final ClearIndicesCacheRequest request, final ActionListener<ClearIndicesCacheResponse> listener) {
|
||||
execute(ClearIndicesCacheAction.INSTANCE, request, listener);
|
||||
|
|
|
@ -304,6 +304,37 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
return mapBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the
|
||||
* alias names for partial matches.
|
||||
*
|
||||
* @param aliases The names of the index aliases to find
|
||||
* @param concreteIndices The concrete indexes the index aliases must point to order to be returned.
|
||||
*
|
||||
* @return whether at least one of the specified aliases exists in one of the specified concrete indices.
|
||||
*/
|
||||
public boolean hasAliases(final String[] aliases, String[] concreteIndices) {
|
||||
assert aliases != null;
|
||||
assert concreteIndices != null;
|
||||
if (concreteIndices.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Sets.SetView<String> intersection = Sets.intersection(Sets.newHashSet(concreteIndices), indices.keySet());
|
||||
for (String index : intersection) {
|
||||
IndexMetaData indexMetaData = indices.get(index);
|
||||
Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() {
|
||||
public boolean apply(String alias) {
|
||||
return Regex.simpleMatch(aliases, alias);
|
||||
}
|
||||
}).values();
|
||||
if (!filteredValues.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the concrete indices.
|
||||
*/
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.elasticsearch.rest.action.admin.indices.alias.RestGetIndicesAliasesAc
|
|||
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.RestIndicesGetAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.head.RestIndicesHeadAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.put.RestIndexPutAliasAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.analyze.RestAnalyzeAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.cache.clear.RestClearIndicesCacheAction;
|
||||
|
@ -123,6 +124,7 @@ public class RestActionModule extends AbstractModule {
|
|||
bind(RestIndicesSegmentsAction.class).asEagerSingleton();
|
||||
bind(RestGetIndicesAliasesAction.class).asEagerSingleton();
|
||||
bind(RestIndicesGetAliasesAction.class).asEagerSingleton();
|
||||
bind(RestIndicesHeadAliasesAction.class).asEagerSingleton();
|
||||
bind(RestIndexDeleteAliasesAction.class).asEagerSingleton();
|
||||
bind(RestIndexPutAliasAction.class).asEagerSingleton();
|
||||
bind(RestIndicesAliasesAction.class).asEagerSingleton();
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* 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.head;
|
||||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesRequest;
|
||||
import org.elasticsearch.action.support.IgnoreIndices;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
||||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RestIndicesHeadAliasesAction extends BaseRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestIndicesHeadAliasesAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(HEAD, "/_alias/{name}", this);
|
||||
controller.registerHandler(HEAD, "/{index}/_alias/{name}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String[] aliases = request.paramAsStringArray("name", Strings.EMPTY_ARRAY);
|
||||
final String[] indices = RestActions.splitIndices(request.param("index"));
|
||||
IndicesGetAliasesRequest getAliasesRequest = new IndicesGetAliasesRequest(aliases);
|
||||
getAliasesRequest.indices(indices);
|
||||
|
||||
if (request.hasParam("ignore_indices")) {
|
||||
getAliasesRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices")));
|
||||
}
|
||||
|
||||
client.admin().indices().existsAliases(getAliasesRequest, new ActionListener<IndicesExistsAliasesResponse>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(IndicesExistsAliasesResponse response) {
|
||||
try {
|
||||
if (response.isExists()) {
|
||||
channel.sendResponse(new StringRestResponse(OK));
|
||||
} else {
|
||||
channel.sendResponse(new StringRestResponse(NOT_FOUND));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
|
||||
} catch (Exception e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.test.integration.aliases;
|
|||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.exists.IndicesExistsAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.IndicesGetAliasesResponse;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -655,31 +656,35 @@ public class IndexAliasesTests extends AbstractNodesTests {
|
|||
assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
logger.info("--> getting alias1");
|
||||
IndicesGetAliasesResponse response = client2.admin().indices().prepareGetAliases("alias1").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).alias(), equalTo("alias1"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
IndicesGetAliasesResponse getResponse = client2.admin().indices().prepareGetAliases("alias1").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias1"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
IndicesExistsAliasesResponse existsResponse = client2.admin().indices().prepareExistsAliases("alias1").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
logger.info("--> getting all aliases that start with alias*");
|
||||
response = client2.admin().indices().prepareGetAliases("alias*").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").size(), equalTo(2));
|
||||
assertThat(response.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).alias(), equalTo("alias2"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(1), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(1).alias(), equalTo("alias1"));
|
||||
assertThat(response.getAliases().get("foobar").get(1).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(1).getSearchRouting(), nullValue());
|
||||
getResponse = client2.admin().indices().prepareGetAliases("alias*").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(2));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("alias2"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(1), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(1).alias(), equalTo("alias1"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(1).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(1).getSearchRouting(), nullValue());
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("alias*").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
logger.info("--> creating aliases [bar, baz, foo]");
|
||||
client1.admin().indices().prepareAliases()
|
||||
|
@ -694,103 +699,124 @@ public class IndexAliasesTests extends AbstractNodesTests {
|
|||
assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
logger.info("--> getting bar and baz for index bazbar");
|
||||
response = client2.admin().indices().prepareGetAliases("bar", "bac").addIndices("bazbar").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("bazbar").size(), equalTo(2));
|
||||
assertThat(response.getAliases().get("bazbar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1), notNullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
|
||||
getResponse = client2.admin().indices().prepareGetAliases("bar", "bac").addIndices("bazbar").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("bar", "bac")
|
||||
.addIndices("bazbar").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
logger.info("--> getting *b* for index baz*");
|
||||
response = client2.admin().indices().prepareGetAliases("*b*").addIndices("baz*").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("bazbar").size(), equalTo(2));
|
||||
assertThat(response.getAliases().get("bazbar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1), notNullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
|
||||
getResponse = client2.admin().indices().prepareGetAliases("*b*").addIndices("baz*").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("*b*")
|
||||
.addIndices("baz*").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
logger.info("--> getting *b* for index *bar");
|
||||
response = client2.admin().indices().prepareGetAliases("b*").addIndices("*bar").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(2));
|
||||
assertThat(response.getAliases().get("bazbar").size(), equalTo(2));
|
||||
assertThat(response.getAliases().get("bazbar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1), notNullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getIndexRouting(), equalTo("bla"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getSearchRouting(), equalTo("bla"));
|
||||
getResponse = client2.admin().indices().prepareGetAliases("b*").addIndices("*bar").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(2));
|
||||
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("term"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("field"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getFilter().string(), containsString("value"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(0).getSearchRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).alias(), equalTo("bar"));
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("bazbar").get(1).getSearchRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("bac"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), equalTo("bla"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), equalTo("bla"));
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("b*")
|
||||
.addIndices("*bar").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
logger.info("--> getting f* for index *bar");
|
||||
response = client2.admin().indices().prepareGetAliases("f*").addIndices("*bar").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
getResponse = client2.admin().indices().prepareGetAliases("f*").addIndices("*bar").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("f*")
|
||||
.addIndices("*bar").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
// alias at work
|
||||
logger.info("--> getting f* for index *bac");
|
||||
response = client2.admin().indices().prepareGetAliases("foo").addIndices("*bac").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
getResponse = client2.admin().indices().prepareGetAliases("foo").addIndices("*bac").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("foo")
|
||||
.addIndices("*bac").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
logger.info("--> getting foo for index foobar");
|
||||
response = client2.admin().indices().prepareGetAliases("foo").addIndices("foobar").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(1));
|
||||
assertThat(response.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
|
||||
assertThat(response.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(response.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
getResponse = client2.admin().indices().prepareGetAliases("foo").addIndices("foobar").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0), notNullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).alias(), equalTo("foo"));
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getFilter(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getIndexRouting(), nullValue());
|
||||
assertThat(getResponse.getAliases().get("foobar").get(0).getSearchRouting(), nullValue());
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("foo")
|
||||
.addIndices("foobar").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
// alias at work again
|
||||
logger.info("--> getting * for index *bac");
|
||||
response = client2.admin().indices().prepareGetAliases("*").addIndices("*bac").execute().actionGet();
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(response.getAliases().size(), equalTo(2));
|
||||
assertThat(response.getAliases().get("foobar").size(), equalTo(4));
|
||||
assertThat(response.getAliases().get("bazbar").size(), equalTo(2));
|
||||
getResponse = client2.admin().indices().prepareGetAliases("*").addIndices("*bac").execute().actionGet();
|
||||
assertThat(getResponse, notNullValue());
|
||||
assertThat(getResponse.getAliases().size(), equalTo(2));
|
||||
assertThat(getResponse.getAliases().get("foobar").size(), equalTo(4));
|
||||
assertThat(getResponse.getAliases().get("bazbar").size(), equalTo(2));
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("*")
|
||||
.addIndices("*bac").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(true));
|
||||
|
||||
indicesAliasesResponse = client2.admin().indices().prepareAliases()
|
||||
.removeAlias("foobar", "foo")
|
||||
|
@ -803,6 +829,9 @@ public class IndexAliasesTests extends AbstractNodesTests {
|
|||
} catch (AliasMissingException e) {
|
||||
assertThat(e.getMessage(), equalTo("alias [foo] missing"));
|
||||
}
|
||||
existsResponse = client2.admin().indices().prepareExistsAliases("foo")
|
||||
.addIndices("foobar").execute().actionGet();
|
||||
assertThat(existsResponse.exists(), equalTo(false));
|
||||
}
|
||||
|
||||
private void assertHits(SearchHits hits, String... ids) {
|
||||
|
|
Loading…
Reference in New Issue