diff --git a/docs/reference/indices.asciidoc b/docs/reference/indices.asciidoc index 616d24ffbbbbe..5fe3d665e0cef 100644 --- a/docs/reference/indices.asciidoc +++ b/docs/reference/indices.asciidoc @@ -24,7 +24,6 @@ and warmers. * <> * <> * <> -* <> * <> [float] @@ -82,8 +81,6 @@ include::indices/get-field-mapping.asciidoc[] include::indices/types-exists.asciidoc[] -include::indices/delete-mapping.asciidoc[] - include::indices/aliases.asciidoc[] include::indices/update-settings.asciidoc[] diff --git a/docs/reference/indices/delete-mapping.asciidoc b/docs/reference/indices/delete-mapping.asciidoc deleted file mode 100644 index 9b72d9cb02f19..0000000000000 --- a/docs/reference/indices/delete-mapping.asciidoc +++ /dev/null @@ -1,25 +0,0 @@ -[[indices-delete-mapping]] -== Delete Mapping - -Allow to delete a mapping (type) along with its data. The REST endpoints are - -[source,js] --------------------------------------------------- - -[DELETE] /{index}/{type} - -[DELETE] /{index}/{type}/_mapping - -[DELETE] /{index}/_mapping/{type} - --------------------------------------------------- - -where - -[horizontal] - -`index`:: `* | _all | glob pattern | name1, name2, …` -`type`:: `* | _all | glob pattern | name1, name2, …` - -Note, most times, it make more sense to reindex the data into a fresh -index compared to delete large chunks of it. diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index a89dcc3763d4b..5c76c79b8b115 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -170,6 +170,7 @@ A `RoutingMissingException` is now thrown instead. === Mappings * The setting `index.mapping.allow_type_wrapper` has been removed. Documents should always be sent without the type as the root element. +* The delete mappings API has been removed. Mapping types can no longer be deleted. ==== Removed type prefix on field names in queries Types can no longer be specified on fields within queries. Instead, specify type restrictions in the search request. diff --git a/rest-api-spec/test/indices.delete_mapping/10_basic.yaml b/rest-api-spec/test/indices.delete_mapping/10_basic.yaml deleted file mode 100644 index bd0f0fe42a6d6..0000000000000 --- a/rest-api-spec/test/indices.delete_mapping/10_basic.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -"delete mapping tests": - - do: - indices.create: - index: test_index - body: - mappings: - test_type: - properties: - text: - type: string - analyzer: whitespace - - - do: - cluster.health: - wait_for_status: yellow - - - do: - indices.exists_type: - index: test_index - type: test_type - - - is_true: '' - - - do: - indices.delete_mapping: - index: test_index - type: test_type - - - do: - indices.exists_type: - index: test_index - type: test_type - - - is_false: '' diff --git a/rest-api-spec/test/indices.delete_mapping/all_path_options.yaml b/rest-api-spec/test/indices.delete_mapping/all_path_options.yaml deleted file mode 100644 index 6e5f9ae7323cb..0000000000000 --- a/rest-api-spec/test/indices.delete_mapping/all_path_options.yaml +++ /dev/null @@ -1,275 +0,0 @@ -setup: - - - do: - indices.create: - index: test_index1 - body: - mappings: { test_type1: { }} - - - do: - indices.create: - index: test_index2 - body: - mappings: { test_type2: { }} - - do: - indices.create: - index: foo - body: - mappings: { test_type2: { }} - - - do: - cluster.health: - wait_for_status: yellow ---- -"delete with _all index": - - do: - indices.delete_mapping: - index: _all - type: test_type2 - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_true: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_false: '' - ---- -"delete with * index": - - do: - indices.delete_mapping: - index: '*' - type: test_type2 - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_true: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_false: '' - ---- -"delete with prefix* index": - - do: - indices.delete_mapping: - index: test* - type: test_type2 - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_true: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_true: '' - ---- -"delete with list of indices": - - - do: - indices.delete_mapping: - index: test_index1,test_index2 - type: test_type2 - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_true: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_true: '' - ---- -"delete with index list and _all type": - - do: - indices.delete_mapping: - index: test_index1,test_index2 - type: _all - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_false: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_true: '' - - ---- -"delete with index list and * type": - - do: - indices.delete_mapping: - index: test_index1,test_index2 - type: '*' - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_false: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_true: '' - - ---- -"delete with index list and prefix* type": - - do: - indices.delete_mapping: - index: test_index1,test_index2 - type: '*2' - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_true: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_true: '' - ---- -"delete with index list and list of types": - - do: - indices.delete_mapping: - index: test_index1,test_index2 - type: test_type1,test_type2 - - - do: - indices.exists_type: - index: test_index1 - type: test_type1 - - - is_false: '' - - - do: - indices.exists_type: - index: test_index2 - type: test_type2 - - - is_false: '' - - - do: - indices.exists_type: - index: foo - type: test_type2 - - - is_true: '' - ---- -"check 404 on no matching type": - - do: - catch: missing - indices.delete_mapping: - index: "*" - type: "non_existent" - - - do: - catch: missing - indices.delete_mapping: - index: "non_existent" - type: "test_type1" - ---- -"check delete with blank index and blank type": - - do: - catch: param - indices.delete_mapping: - name: "test_type1" - - - do: - catch: param - indices.delete_mapping: - index: "test_index1" - diff --git a/src/main/java/org/elasticsearch/action/ActionModule.java b/src/main/java/org/elasticsearch/action/ActionModule.java index 5e6dc779dbf71..21df6223a28b0 100644 --- a/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/src/main/java/org/elasticsearch/action/ActionModule.java @@ -86,8 +86,6 @@ import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; import org.elasticsearch.action.admin.indices.get.GetIndexAction; import org.elasticsearch.action.admin.indices.get.TransportGetIndexAction; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingAction; -import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction; import org.elasticsearch.action.admin.indices.mapping.get.*; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction; @@ -254,7 +252,6 @@ protected void configure() { registerAction(GetMappingsAction.INSTANCE, TransportGetMappingsAction.class); registerAction(GetFieldMappingsAction.INSTANCE, TransportGetFieldMappingsAction.class, TransportGetFieldMappingsIndexAction.class); registerAction(PutMappingAction.INSTANCE, TransportPutMappingAction.class); - registerAction(DeleteMappingAction.INSTANCE, TransportDeleteMappingAction.class); registerAction(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class); registerAction(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class); registerAction(AnalyzeAction.INSTANCE, TransportAnalyzeAction.class); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingAction.java deleted file mode 100644 index f4792ef79d889..0000000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingAction.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; - -/** - */ -public class DeleteMappingAction extends IndicesAction { - - public static final DeleteMappingAction INSTANCE = new DeleteMappingAction(); - public static final String NAME = "indices:admin/mapping/delete"; - - private DeleteMappingAction() { - super(NAME); - } - - @Override - public DeleteMappingResponse newResponse() { - return new DeleteMappingResponse(); - } - - @Override - public DeleteMappingRequestBuilder newRequestBuilder(IndicesAdminClient client) { - return new DeleteMappingRequestBuilder(client); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingClusterStateUpdateRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingClusterStateUpdateRequest.java deleted file mode 100644 index 5a2ef82eba17e..0000000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingClusterStateUpdateRequest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import org.elasticsearch.cluster.ack.IndicesClusterStateUpdateRequest; - -/** - * Cluster state update request that allows to delete a mapping - */ -public class DeleteMappingClusterStateUpdateRequest extends IndicesClusterStateUpdateRequest { - - private String[] types; - - DeleteMappingClusterStateUpdateRequest() { - - } - - /** - * Returns the type to be removed - */ - public String[] types() { - return types; - } - - /** - * Sets the type to be removed - */ - public DeleteMappingClusterStateUpdateRequest types(String[] types) { - this.types = types; - return this; - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java deleted file mode 100644 index c758e428a348f..0000000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.IndicesRequest; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.util.CollectionUtils; - -import java.io.IOException; - -import static org.elasticsearch.action.ValidateActions.addValidationError; - -/** - * Represents a request to delete a mapping - */ -public class DeleteMappingRequest extends AcknowledgedRequest implements IndicesRequest.Replaceable { - - private String[] indices; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false); - private String[] types; - - DeleteMappingRequest() { - } - - /** - * Constructs a new delete mapping request against one or more indices. If nothing is set then - * it will be executed against all indices. - */ - public DeleteMappingRequest(String... indices) { - this.indices = indices; - } - - @Override - public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = null; - if (CollectionUtils.isEmpty(types)) { - validationException = addValidationError("mapping type is missing", validationException); - } else { - validationException = checkForEmptyString(validationException, types); - } - if (CollectionUtils.isEmpty(indices)) { - validationException = addValidationError("index is missing", validationException); - } else { - validationException = checkForEmptyString(validationException, indices); - } - - return validationException; - } - - private ActionRequestValidationException checkForEmptyString(ActionRequestValidationException validationException, String[] strings) { - boolean containsEmptyString = false; - for (String string : strings) { - if (!Strings.hasText(string)) { - containsEmptyString = true; - } - } - if (containsEmptyString) { - validationException = addValidationError("types must not contain empty strings", validationException); - } - return validationException; - } - - /** - * Sets the indices this delete mapping operation will execute on. - */ - @Override - public DeleteMappingRequest indices(String[] indices) { - this.indices = indices; - return this; - } - - /** - * The indices the mappings will be removed from. - */ - @Override - public String[] indices() { - return indices; - } - - @Override - public IndicesOptions indicesOptions() { - return indicesOptions; - } - - public DeleteMappingRequest indicesOptions(IndicesOptions indicesOptions) { - this.indicesOptions = indicesOptions; - return this; - } - - /** - * The mapping types. - */ - public String[] types() { - return types; - } - - /** - * The type of the mappings to remove. - */ - public DeleteMappingRequest types(String... types) { - this.types = types; - return this; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - indices = in.readStringArray(); - indicesOptions = IndicesOptions.readIndicesOptions(in); - types = in.readStringArray(); - readTimeout(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeStringArrayNullable(indices); - indicesOptions.writeIndicesOptions(out); - out.writeStringArrayNullable(types); - writeTimeout(out); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java deleted file mode 100644 index 445fa8d8ca08b..0000000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder; -import org.elasticsearch.client.IndicesAdminClient; - -/** - * Builder for a delete mapping request - */ -public class DeleteMappingRequestBuilder extends AcknowledgedRequestBuilder { - - public DeleteMappingRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteMappingRequest()); - } - - /** - * Sets the indices the delete mapping will execute on - */ - public DeleteMappingRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; - } - - /** - * Sets the type of the mapping to remove - */ - public DeleteMappingRequestBuilder setType(String... types) { - request.types(types); - return this; - } - - /** - * Specifies what type of requested indices to ignore and wildcard indices expressions. - * - * For example indices that don't exist. - */ - public DeleteMappingRequestBuilder setIndicesOptions(IndicesOptions options) { - request.indicesOptions(options); - return this; - } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteMapping(request, listener); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingResponse.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingResponse.java deleted file mode 100644 index e1498cab4e5bf..0000000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingResponse.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; - -/** - * The response of remove mapping operation. - */ -public class DeleteMappingResponse extends AcknowledgedResponse { - - DeleteMappingResponse() { - - } - - DeleteMappingResponse(boolean acknowledged) { - super(acknowledged); - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java deleted file mode 100644 index 02d1b798e177d..0000000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/TransportDeleteMappingAction.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ActionWriteResponse; -import org.elasticsearch.action.ShardOperationFailedException; -import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.flush.FlushResponse; -import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; -import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction; -import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest; -import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; -import org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse; -import org.elasticsearch.action.deletebyquery.TransportDeleteByQueryAction; -import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.action.support.DestructiveOperations; -import org.elasticsearch.action.support.QuerySourceBuilder; -import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse; -import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; -import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.cluster.block.ClusterBlockLevel; -import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.cluster.metadata.MetaDataMappingService; -import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.query.BoolFilterBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.TypeFilterBuilder; -import org.elasticsearch.indices.TypeMissingException; -import org.elasticsearch.node.settings.NodeSettingsService; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.HashSet; -import java.util.Set; - -/** - * Delete mapping action. - */ -public class TransportDeleteMappingAction extends TransportMasterNodeOperationAction { - - private final MetaDataMappingService metaDataMappingService; - private final TransportFlushAction flushAction; - private final TransportDeleteByQueryAction deleteByQueryAction; - private final TransportRefreshAction refreshAction; - private final DestructiveOperations destructiveOperations; - - @Inject - public TransportDeleteMappingAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, MetaDataMappingService metaDataMappingService, - TransportDeleteByQueryAction deleteByQueryAction, TransportRefreshAction refreshAction, - TransportFlushAction flushAction, NodeSettingsService nodeSettingsService, ActionFilters actionFilters) { - super(settings, DeleteMappingAction.NAME, transportService, clusterService, threadPool, actionFilters); - this.metaDataMappingService = metaDataMappingService; - this.deleteByQueryAction = deleteByQueryAction; - this.refreshAction = refreshAction; - this.flushAction = flushAction; - this.destructiveOperations = new DestructiveOperations(logger, settings, nodeSettingsService); - } - - @Override - protected String executor() { - // no need for fork on another thread pool, we go async right away - return ThreadPool.Names.SAME; - } - - @Override - protected DeleteMappingRequest newRequest() { - return new DeleteMappingRequest(); - } - - @Override - protected DeleteMappingResponse newResponse() { - return new DeleteMappingResponse(); - } - - @Override - protected void doExecute(DeleteMappingRequest request, ActionListener listener) { - destructiveOperations.failDestructive(request.indices()); - super.doExecute(request, listener); - } - - @Override - protected ClusterBlockException checkBlock(DeleteMappingRequest request, ClusterState state) { - return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, state.metaData().concreteIndices(request.indicesOptions(), request.indices())); - } - - @Override - protected void masterOperation(final DeleteMappingRequest request, final ClusterState state, final ActionListener listener) throws ElasticsearchException { - final String[] concreteIndices = state.metaData().concreteIndices(request.indicesOptions(), request.indices()); - flushAction.execute(new FlushRequest(request).indices(concreteIndices), new ActionListener() { - @Override - public void onResponse(FlushResponse flushResponse) { - if (logger.isTraceEnabled()) { - traceLogResponse("Flush", flushResponse); - } - - // get all types that need to be deleted. - ImmutableOpenMap> result = clusterService.state().metaData().findMappings( - concreteIndices, request.types() - ); - // create OrFilter with type filters within to account for different types - BoolFilterBuilder filterBuilder = new BoolFilterBuilder(); - Set types = new HashSet<>(); - for (ObjectObjectCursor> typesMeta : result) { - for (ObjectObjectCursor type : typesMeta.value) { - filterBuilder.should(new TypeFilterBuilder(type.key)); - types.add(type.key); - } - } - if (types.size() == 0) { - throw new TypeMissingException(new Index("_all"), request.types(), "No index has the type."); - } - request.types(types.toArray(new String[types.size()])); - QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder() - .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filterBuilder)); - - DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(request).indices(concreteIndices).types(request.types()).source(querySourceBuilder); - deleteByQueryAction.execute(deleteByQueryRequest, new ActionListener() { - @Override - public void onResponse(DeleteByQueryResponse deleteByQueryResponse) { - if (logger.isTraceEnabled()) { - for (IndexDeleteByQueryResponse indexResponse : deleteByQueryResponse) { - logger.trace("Delete by query for index [{}] completed with total[{}], successful[{}] and failed[{}]", indexResponse.getIndex(), indexResponse.getShardInfo().getTotal(), indexResponse.getShardInfo().getSuccessful(), indexResponse.getShardInfo().getFailed()); - for (ActionWriteResponse.ShardInfo.Failure failure : indexResponse.getShardInfo().getFailures()) { - logger.trace("[{}/{}/{}/{}] Delete by query shard failure reason: {}", failure.index(), failure.shardId(), failure.primary(), failure.nodeId(), failure.reason()); - } - } - } - refreshAction.execute(new RefreshRequest(request).indices(concreteIndices), new ActionListener() { - @Override - public void onResponse(RefreshResponse refreshResponse) { - if (logger.isTraceEnabled()) { - traceLogResponse("Refresh", refreshResponse); - } - removeMapping(); - } - - @Override - public void onFailure(Throwable e) { - if (logger.isDebugEnabled()) { - logger.debug("Refresh failed completely", e); - } - removeMapping(); - } - - protected void removeMapping() { - DeleteMappingClusterStateUpdateRequest clusterStateUpdateRequest = new DeleteMappingClusterStateUpdateRequest() - .indices(concreteIndices).types(request.types()) - .ackTimeout(request.timeout()) - .masterNodeTimeout(request.masterNodeTimeout()); - - metaDataMappingService.removeMapping(clusterStateUpdateRequest, new ActionListener() { - @Override - public void onResponse(ClusterStateUpdateResponse response) { - listener.onResponse(new DeleteMappingResponse(response.isAcknowledged())); - } - - @Override - public void onFailure(Throwable t) { - listener.onFailure(t); - } - }); - } - }); - } - - @Override - public void onFailure(Throwable t) { - listener.onFailure(t); - } - }); - } - - @Override - public void onFailure(Throwable t) { - listener.onFailure(t); - } - }); - } - - private void traceLogResponse(String action, BroadcastOperationResponse response) { - logger.trace("{} completed with total[{}], successful[{}] and failed[{}]", action, response.getTotalShards(), response.getSuccessfulShards(), response.getFailedShards()); - if (response.getFailedShards() > 0) { - for (ShardOperationFailedException failure : response.getShardFailures()) { - logger.trace("[{}/{}] {} shard failure reason: {}", failure.index(), failure.shardId(), action, failure.reason()); - } - } - } -} diff --git a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 609a5450e8472..0852643444a4e 100644 --- a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -56,9 +56,6 @@ import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequestBuilder; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingResponse; import org.elasticsearch.action.admin.indices.mapping.get.*; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; @@ -438,29 +435,6 @@ public interface IndicesAdminClient extends ElasticsearchClient deleteMapping(DeleteMappingRequest request); - - /** - * Deletes mapping definition for a type into one or more indices. - * - * @param request The delete mapping request - * @param listener A listener to be notified with a result - * @see org.elasticsearch.client.Requests#deleteMappingRequest(String...) - */ - void deleteMapping(DeleteMappingRequest request, ActionListener listener); - - /** - * Deletes mapping definition for a type into one or more indices. - */ - DeleteMappingRequestBuilder prepareDeleteMapping(String... indices); - /** * Allows to add/remove aliases from indices. * diff --git a/src/main/java/org/elasticsearch/client/Requests.java b/src/main/java/org/elasticsearch/client/Requests.java index 8e1518fe2d53c..d8717ffb0955f 100644 --- a/src/main/java/org/elasticsearch/client/Requests.java +++ b/src/main/java/org/elasticsearch/client/Requests.java @@ -44,7 +44,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; @@ -277,17 +276,6 @@ public static PutMappingRequest putMappingRequest(String... indices) { return new PutMappingRequest(indices); } - /** - * Deletes mapping (and all its data) from one or more indices. - * - * @param indices The indices the mapping will be deleted from. Use null or _all to execute against all indices - * @return The create mapping request - * @see org.elasticsearch.client.IndicesAdminClient#deleteMapping(org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest) - */ - public static DeleteMappingRequest deleteMappingRequest(String... indices) { - return new DeleteMappingRequest(indices); - } - /** * Creates an index aliases request allowing to add and remove aliases. * diff --git a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java index 143df3bacc1eb..02f8a01517073 100644 --- a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java @@ -67,10 +67,6 @@ import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingAction; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequestBuilder; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingResponse; import org.elasticsearch.action.admin.indices.mapping.get.*; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; @@ -374,21 +370,6 @@ public PutMappingRequestBuilder preparePutMapping(String... indices) { return new PutMappingRequestBuilder(this).setIndices(indices); } - @Override - public ActionFuture deleteMapping(final DeleteMappingRequest request) { - return execute(DeleteMappingAction.INSTANCE, request); - } - - @Override - public void deleteMapping(final DeleteMappingRequest request, final ActionListener listener) { - execute(DeleteMappingAction.INSTANCE, request, listener); - } - - @Override - public DeleteMappingRequestBuilder prepareDeleteMapping(String... indices) { - return new DeleteMappingRequestBuilder(this).setIndices(indices); - } - @Override public ActionFuture optimize(final OptimizeRequest request) { return execute(OptimizeAction.INSTANCE, request); diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 476edb0d6e0da..fb702943744a0 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -23,7 +23,6 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingClusterStateUpdateRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest; import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterService; @@ -407,54 +406,6 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS }); } - public void removeMapping(final DeleteMappingClusterStateUpdateRequest request, final ActionListener listener) { - clusterService.submitStateUpdateTask("remove-mapping [" + Arrays.toString(request.types()) + "]", Priority.HIGH, new AckedClusterStateUpdateTask(request, listener) { - @Override - protected ClusterStateUpdateResponse newResponse(boolean acknowledged) { - return new ClusterStateUpdateResponse(acknowledged); - } - - @Override - public ClusterState execute(ClusterState currentState) { - if (request.indices().length == 0) { - throw new IndexMissingException(new Index("_all")); - } - - MetaData.Builder builder = MetaData.builder(currentState.metaData()); - boolean changed = false; - String latestIndexWithout = null; - for (String indexName : request.indices()) { - IndexMetaData indexMetaData = currentState.metaData().index(indexName); - IndexMetaData.Builder indexBuilder = IndexMetaData.builder(indexMetaData); - - if (indexMetaData != null) { - boolean isLatestIndexWithout = true; - for (String type : request.types()) { - if (indexMetaData.mappings().containsKey(type)) { - indexBuilder.removeMapping(type); - changed = true; - isLatestIndexWithout = false; - } - } - if (isLatestIndexWithout) { - latestIndexWithout = indexMetaData.index(); - } - - } - builder.put(indexBuilder); - } - - if (!changed) { - throw new TypeMissingException(new Index(latestIndexWithout), request.types()); - } - - logger.info("[{}] remove_mapping [{}]", request.indices(), request.types()); - - return ClusterState.builder(currentState).metaData(builder).build(); - } - }); - } - public void putMapping(final PutMappingClusterStateUpdateRequest request, final ActionListener listener) { clusterService.submitStateUpdateTask("put-mapping [" + request.type() + "]", Priority.HIGH, new AckedClusterStateUpdateTask(request, listener) { diff --git a/src/main/java/org/elasticsearch/rest/action/RestActionModule.java b/src/main/java/org/elasticsearch/rest/action/RestActionModule.java index d071a389967fe..9bc0d98905838 100644 --- a/src/main/java/org/elasticsearch/rest/action/RestActionModule.java +++ b/src/main/java/org/elasticsearch/rest/action/RestActionModule.java @@ -60,7 +60,6 @@ import org.elasticsearch.rest.action.admin.indices.exists.types.RestTypesExistsAction; import org.elasticsearch.rest.action.admin.indices.flush.RestFlushAction; import org.elasticsearch.rest.action.admin.indices.get.RestGetIndicesAction; -import org.elasticsearch.rest.action.admin.indices.mapping.delete.RestDeleteMappingAction; import org.elasticsearch.rest.action.admin.indices.mapping.get.RestGetFieldMappingAction; import org.elasticsearch.rest.action.admin.indices.mapping.get.RestGetMappingAction; import org.elasticsearch.rest.action.admin.indices.mapping.put.RestPutMappingAction; @@ -181,7 +180,6 @@ protected void configure() { bind(RestGetWarmerAction.class).asEagerSingleton(); bind(RestPutMappingAction.class).asEagerSingleton(); - bind(RestDeleteMappingAction.class).asEagerSingleton(); bind(RestGetMappingAction.class).asEagerSingleton(); bind(RestGetFieldMappingAction.class).asEagerSingleton(); diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java deleted file mode 100644 index db1382d1d7001..0000000000000 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/delete/RestDeleteMappingAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to Elasticsearch 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.mapping.delete; - -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingResponse; -import org.elasticsearch.action.support.IndicesOptions; -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.AcknowledgedRestListener; - -import static org.elasticsearch.client.Requests.deleteMappingRequest; -import static org.elasticsearch.rest.RestRequest.Method.DELETE; - -/** - * - */ -public class RestDeleteMappingAction extends BaseRestHandler { - - @Inject - public RestDeleteMappingAction(Settings settings, RestController controller, Client client) { - super(settings, controller, client); - controller.registerHandler(DELETE, "/{index}/{type}/_mapping", this); - controller.registerHandler(DELETE, "/{index}/{type}", this); - controller.registerHandler(DELETE, "/{index}/_mapping/{type}", this); - - //support _mappings also - controller.registerHandler(DELETE, "/{index}/{type}/_mappings", this); - controller.registerHandler(DELETE, "/{index}/_mappings/{type}", this); - } - - @Override - public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { - DeleteMappingRequest deleteMappingRequest = deleteMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); - deleteMappingRequest.listenerThreaded(false); - deleteMappingRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); - deleteMappingRequest.timeout(request.paramAsTime("timeout", deleteMappingRequest.timeout())); - deleteMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteMappingRequest.masterNodeTimeout())); - deleteMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteMappingRequest.indicesOptions())); - client.admin().indices().deleteMapping(deleteMappingRequest, new AcknowledgedRestListener(channel)); - } -} diff --git a/src/main/java/org/elasticsearch/river/RiversService.java b/src/main/java/org/elasticsearch/river/RiversService.java index ecb1163b6f923..f9a801e120fbc 100644 --- a/src/main/java/org/elasticsearch/river/RiversService.java +++ b/src/main/java/org/elasticsearch/river/RiversService.java @@ -26,7 +26,6 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.WriteConsistencyLevel; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingResponse; import org.elasticsearch.action.get.GetRequestBuilder; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.Client; @@ -36,14 +35,12 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Injector; -import org.elasticsearch.common.inject.Injectors; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.river.cluster.RiverClusterChangedEvent; import org.elasticsearch.river.cluster.RiverClusterService; @@ -214,37 +211,6 @@ public void riverClusterChanged(RiverClusterChangedEvent event) { if (routing == null || !localNode.equals(routing.node())) { // not routed at all, and not allocated here, clean it (we delete the relevant ones before) closeRiver(riverName); - // also, double check and delete the river content if it was deleted (_meta does not exists) - try { - client.prepareGet(riverIndexName, riverName.name(), "_meta").setListenerThreaded(true).execute(new ActionListener() { - @Override - public void onResponse(GetResponse getResponse) { - if (!getResponse.isExists()) { - // verify the river is deleted - client.admin().indices().prepareDeleteMapping(riverIndexName).setType(riverName.name()).execute(new ActionListener() { - @Override - public void onResponse(DeleteMappingResponse deleteMappingResponse) { - // all is well... - } - - @Override - public void onFailure(Throwable e) { - logger.debug("failed to (double) delete river [{}] content", e, riverName.name()); - } - }); - } - } - - @Override - public void onFailure(Throwable e) { - logger.debug("failed to (double) delete river [{}] content", e, riverName.name()); - } - }); - } catch (IndexMissingException e) { - // all is well, the _river index was deleted - } catch (Exception e) { - logger.warn("unexpected failure when trying to verify river [{}] deleted", e, riverName.name()); - } } } diff --git a/src/test/java/org/elasticsearch/action/IndicesRequestTests.java b/src/test/java/org/elasticsearch/action/IndicesRequestTests.java index 4c5d19300076f..84323360b60e9 100644 --- a/src/test/java/org/elasticsearch/action/IndicesRequestTests.java +++ b/src/test/java/org/elasticsearch/action/IndicesRequestTests.java @@ -30,8 +30,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.flush.FlushAction; import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingAction; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsAction; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction; @@ -609,19 +607,6 @@ public void testPutMapping() { assertSameIndices(putMappingRequest, PutMappingAction.NAME); } - @Test - public void testDeleteMapping() { - interceptTransportActions(DeleteMappingAction.NAME); - - String[] indices = randomUniqueIndicesOrAliases(); - client().admin().indices().putMapping(new PutMappingRequest(indices).type("type").source("field", "type=string")).actionGet(); - DeleteMappingRequest deleteMappingRequest = new DeleteMappingRequest(indices).types("type"); - internalCluster().clientNodeClient().admin().indices().deleteMapping(deleteMappingRequest).actionGet(); - - clearInterceptedActions(); - assertSameIndices(deleteMappingRequest, DeleteMappingAction.NAME); - } - @Test public void testGetSettings() { interceptTransportActions(GetSettingsAction.NAME); diff --git a/src/test/java/org/elasticsearch/cluster/BlockClusterStatsTests.java b/src/test/java/org/elasticsearch/cluster/BlockClusterStatsTests.java index e0865ba0eb068..31abbc2c020d8 100644 --- a/src/test/java/org/elasticsearch/cluster/BlockClusterStatsTests.java +++ b/src/test/java/org/elasticsearch/cluster/BlockClusterStatsTests.java @@ -63,13 +63,6 @@ public void testBlocks() throws Exception { assertClusterAndIndexBlocks(e); } - try { - client().admin().indices().prepareDeleteMapping("foo-alias").setType("test").get(); - fail("delete mapping should have failed"); - } catch(ClusterBlockException e) { - assertClusterAndIndexBlocks(e); - } - try { client().admin().indices().preparePutMapping("foo-alias").setType("type1").setSource("field1", "type=string").get(); fail("put mapping should have failed"); diff --git a/src/test/java/org/elasticsearch/cluster/ack/AckTests.java b/src/test/java/org/elasticsearch/cluster/ack/AckTests.java index 974539ceaa801..e1da078e3eb23 100644 --- a/src/test/java/org/elasticsearch/cluster/ack/AckTests.java +++ b/src/test/java/org/elasticsearch/cluster/ack/AckTests.java @@ -27,10 +27,8 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; -import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse; import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse; import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; @@ -177,37 +175,6 @@ public boolean apply(Object input) { })); } - @Test - public void testDeleteMappingAcknowledgement() { - client().admin().indices().prepareCreate("test") - .addMapping("type1", "field1", "type=string").get(); - ensureGreen(); - - client().prepareIndex("test", "type1").setSource("field1", "value1"); - - GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").addTypes("type1").get(); - assertThat(getMappingsResponse.mappings().get("test").get("type1"), notNullValue()); - - assertAcked(client().admin().indices().prepareDeleteMapping("test").setType("type1")); - - for (Client client : clients()) { - getMappingsResponse = client.admin().indices().prepareGetMappings("test").addTypes("type1").setLocal(true).get(); - assertThat(getMappingsResponse.mappings().size(), equalTo(0)); - } - } - - @Test - public void testDeleteMappingNoAcknowledgement() { - client().admin().indices().prepareCreate("test") - .addMapping("type1", "field1", "type=string").get(); - ensureGreen(); - - client().prepareIndex("test", "type1").setSource("field1", "value1"); - - DeleteMappingResponse deleteMappingResponse = client().admin().indices().prepareDeleteMapping("test").setTimeout("0s").setType("type1").get(); - assertThat(deleteMappingResponse.isAcknowledged(), equalTo(false)); - } - @Test public void testClusterRerouteAcknowledgement() throws InterruptedException { assertAcked(prepareCreate("test").setSettings(ImmutableSettings.builder() diff --git a/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java b/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java index 0b85d136858af..e036b93333448 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java @@ -630,46 +630,7 @@ public void testDeleteIndex_wildcard() throws Exception { assertThat(client().admin().indices().prepareExists("bar").get().isExists(), equalTo(false)); assertThat(client().admin().indices().prepareExists("barbaz").get().isExists(), equalTo(false)); } - - @Test - public void testDeleteMapping() throws Exception { - assertAcked(prepareCreate("foobar").addMapping("type1", "field", "type=string")); - ensureGreen(); - - verify(client().admin().indices().prepareDeleteMapping("foo").setType("type1"), true); - assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type1").get().isExists(), equalTo(true)); - verify(client().admin().indices().prepareDeleteMapping("foobar").setType("type1"), false); - assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type1").get().isExists(), equalTo(false)); - } - - @Test - public void testDeleteMapping_wildcard() throws Exception { - verify(client().admin().indices().prepareDeleteMapping("_all").setType("type1"), true); - - assertAcked(prepareCreate("foo").addMapping("type1", "field", "type=string")); - assertAcked(prepareCreate("foobar").addMapping("type1", "field", "type=string")); - assertAcked(prepareCreate("bar").addMapping("type1", "field", "type=string")); - assertAcked(prepareCreate("barbaz").addMapping("type1", "field", "type=string")); - // we wait for green to make sure indices with mappings have been created on all relevant - // nodes, and that recovery won't re-introduce a mapping - ensureGreen(); - - verify(client().admin().indices().prepareDeleteMapping("foo*").setType("type1"), false); - assertThat(client().admin().indices().prepareTypesExists("foo").setTypes("type1").get().isExists(), equalTo(false)); - assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type1").get().isExists(), equalTo(false)); - assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type1").get().isExists(), equalTo(true)); - assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type1").get().isExists(), equalTo(true)); - - assertAcked(client().admin().indices().prepareDelete("foo*")); - - verify(client().admin().indices().prepareDeleteMapping("foo*").setType("type1"), true); - - verify(client().admin().indices().prepareDeleteMapping("_all").setType("type1"), false); - assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type1").get().isExists(), equalTo(false)); - assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type1").get().isExists(), equalTo(false)); - } - - + @Test public void testPutWarmer() throws Exception { createIndex("foobar"); @@ -727,37 +688,7 @@ public void testPutAlias_wildcard() throws Exception { assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("barbaz").get().exists(), equalTo(true)); } - @Test - public void testDeleteMapping_typeWildcard() throws Exception { - verify(client().admin().indices().prepareDeleteMapping("_all").setType("type1"), true); - - assertAcked(prepareCreate("foo").addMapping("type1", "field", "type=string")); - assertAcked(prepareCreate("foobar").addMapping("type2", "field", "type=string")); - assertAcked(prepareCreate("bar").addMapping("type3", "field", "type=string")); - assertAcked(prepareCreate("barbaz").addMapping("type4", "field", "type=string")); - - ensureGreen(); - - assertThat(client().admin().indices().prepareTypesExists("foo").setTypes("type1").get().isExists(), equalTo(true)); - assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type2").get().isExists(), equalTo(true)); - assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type3").get().isExists(), equalTo(true)); - assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type4").get().isExists(), equalTo(true)); - - verify(client().admin().indices().prepareDeleteMapping("foo*").setType("type*"), false); - assertThat(client().admin().indices().prepareTypesExists("foo").setTypes("type1").get().isExists(), equalTo(false)); - assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type2").get().isExists(), equalTo(false)); - assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type3").get().isExists(), equalTo(true)); - assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type4").get().isExists(), equalTo(true)); - - assertAcked(client().admin().indices().prepareDelete("foo*")); - - verify(client().admin().indices().prepareDeleteMapping("foo*").setType("type1"), true); - - verify(client().admin().indices().prepareDeleteMapping("_all").setType("type3","type4"), false); - assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type3").get().isExists(), equalTo(false)); - assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type4").get().isExists(), equalTo(false)); - } - + @Test public void testDeleteWarmer() throws Exception { IndexWarmersMetaData.Entry entry = new IndexWarmersMetaData.Entry( diff --git a/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java b/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java deleted file mode 100644 index af97fe72a3441..0000000000000 --- a/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to Elasticsearch 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.indices.mapping; - -import com.google.common.base.Predicate; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; -import org.elasticsearch.action.count.CountResponse; -import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.test.ElasticsearchIntegrationTest; -import org.junit.Test; - -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; - -/** - * - */ -public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest { - - @Test - public void simpleDeleteMapping() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", "value", "type=string").execute().actionGet()); - for (int i = 0; i < 10; i++) { - client().prepareIndex("test", "type1", Integer.toString(i)).setSource(jsonBuilder().startObject() - .field("value", "test" + i) - .endObject()).execute().actionGet(); - } - - ensureGreen(); - refresh(); - - for (int i = 0; i < 10; i++) { - CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(); - assertThat(countResponse.getCount(), equalTo(10l)); - } - - waitForMappingOnMaster("test", "type1"); - - GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings("test").setTypes("type1").execute().actionGet(); - assertThat(mappingsResponse.getMappings().get("test").get("type1"), notNullValue()); - - assertAcked(client().admin().indices().prepareDeleteMapping().setIndices("test").setType("type1")); - - for (int i = 0; i < 10; i++) { - CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(); - assertThat(countResponse.getCount(), equalTo(0l)); - } - assertBusy(new Runnable() { - @Override - public void run() { - GetMappingsResponse response = client().admin().indices().prepareGetMappings().get(); - assertTrue(response.getMappings().containsKey("test")); - assertFalse(response.getMappings().get("test").containsKey("type1")); - } - }); - } - - - @Test - public void deleteMappingAllowNoBlankIndexAndNoEmptyStrings() throws Exception { - assertAcked(client().admin().indices().prepareCreate("index1").addMapping("1", "field1", "type=string").get()); - assertAcked(client().admin().indices().prepareCreate("1index").addMapping("1", "field1", "type=string").get()); - - // Should succeed, since no wildcards - client().admin().indices().prepareDeleteMapping("1index").setType("1").get(); - try { - client().admin().indices().prepareDeleteMapping("_all").get(); - fail(); - } catch (ActionRequestValidationException e) {} - - try { - client().admin().indices().prepareDeleteMapping("_all").setType("").get(); - fail(); - } catch (ActionRequestValidationException e) {} - - try { - client().admin().indices().prepareDeleteMapping().setType("1").get(); - fail(); - } catch (ActionRequestValidationException e) {} - - try { - client().admin().indices().prepareDeleteMapping("").setType("1").get(); - fail(); - } catch (ActionRequestValidationException e) {} - - } - -} diff --git a/src/test/java/org/elasticsearch/operateAllIndices/DestructiveOperationsIntegrationTests.java b/src/test/java/org/elasticsearch/operateAllIndices/DestructiveOperationsIntegrationTests.java index d752bdea3e2df..9815887f1d1c4 100644 --- a/src/test/java/org/elasticsearch/operateAllIndices/DestructiveOperationsIntegrationTests.java +++ b/src/test/java/org/elasticsearch/operateAllIndices/DestructiveOperationsIntegrationTests.java @@ -144,36 +144,6 @@ public void testDestructiveOperations() throws Exception { client().prepareDeleteByQuery().setQuery(QueryBuilders.matchAllQuery()).get(); // end delete_by_query: client().admin().indices().prepareDelete("_all").get(); - // delete mapping: - settings = ImmutableSettings.builder() - .put(DestructiveOperations.REQUIRES_NAME, true) - .build(); - assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings)); - - - assertAcked(client().admin().indices().prepareCreate("index1").addMapping("1", "field1", "type=string").get()); - assertAcked(client().admin().indices().prepareCreate("1index").addMapping("1", "field1", "type=string").get()); - - // Should succeed, since no wildcards - client().admin().indices().prepareDeleteMapping("1index").setType("1").get(); - try { - client().admin().indices().prepareDeleteMapping("_all").setType("1").get(); - fail(); - } catch (ElasticsearchIllegalArgumentException e) { - } - try { - client().admin().indices().prepareDeleteMapping().setIndices("*").setType("1").get(); - fail(); - } catch (ElasticsearchIllegalArgumentException e) { - } - - settings = ImmutableSettings.builder().put(DestructiveOperations.REQUIRES_NAME, false).build(); - assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings)); - - assertAcked(client().admin().indices().preparePutMapping("1index").setType("1").setSource("field1", "type=string")); - assertAcked(client().admin().indices().prepareDeleteMapping().setIndices("*").setType("1")); - assertAcked(client().admin().indices().preparePutMapping("1index").setType("1").setSource("field1", "type=string")); - assertAcked(client().admin().indices().prepareDeleteMapping("_all").setType("1")); } } diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java index d6b9bd852d1ec..fcb92835378ef 100644 --- a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java @@ -1654,63 +1654,6 @@ public int compare(PercolateResponse.Match a, PercolateResponse.Match b) { assertThat(matches[4].getHighlightFields().get("field1").fragments()[0].string(), equalTo("The quick brown fox jumps over the lazy dog")); } - @Test - public void testDeletePercolatorType() throws Exception { - assertAcked(client().admin().indices().prepareCreate("test1")); - assertAcked(client().admin().indices().prepareCreate("test2")); - - client().prepareIndex("test1", PercolatorService.TYPE_NAME, "1") - .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) - .execute().actionGet(); - client().prepareIndex("test2", PercolatorService.TYPE_NAME, "1") - .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) - .execute().actionGet(); - - PercolateResponse response = client().preparePercolate() - .setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true) - .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject())) - .execute().actionGet(); - assertMatchCount(response, 2l); - - awaitBusy(new Predicate() { - @Override - public boolean apply(Object o) { - for (Client client : internalCluster()) { - GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings("test1", "test2").get(); - boolean hasPercolatorType = getMappingsResponse.getMappings().get("test1").containsKey(PercolatorService.TYPE_NAME); - if (!hasPercolatorType) { - return false; - } - - if (!getMappingsResponse.getMappings().get("test2").containsKey(PercolatorService.TYPE_NAME)) { - return false; - } - } - return true; - } - }); - - ensureGreen("test1", "test2"); - - assertAcked(client().admin().indices().prepareDeleteMapping("test1").setType(PercolatorService.TYPE_NAME)); - response = client().preparePercolate() - .setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true) - .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject())) - .execute().actionGet(); - assertMatchCount(response, 1l); - - assertAcked(client().admin().indices().prepareDeleteMapping("test2").setType(PercolatorService.TYPE_NAME)); - // Percolate api should return 0 matches, because all docs in _percolate type have been removed. - response = client().preparePercolate() - .setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true) - .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject())) - .execute().actionGet(); - assertMatchCount(response, 0l); - - SearchResponse searchResponse = client().prepareSearch("test1", "test2").get(); - assertHitCount(searchResponse, 0); - } - public static String[] convertFromTextArray(PercolateResponse.Match[] matches, String index) { if (matches.length == 0) { return Strings.EMPTY_ARRAY;