Mappings: Remove delete mapping API

Deleting a type from an index is inherently dangerous because
the type can be recreated with new mappings which may conflict
with existing segments still using the old mappings. This
removes the ability to delete a type (similar to how deleting
fields within a type is not allowed, for the same reason).

closes #8877
closes #10231
This commit is contained in:
Ryan Ernst 2015-03-23 17:28:02 -07:00
parent 9c0f655674
commit 693d91e41c
26 changed files with 3 additions and 1441 deletions

View File

@ -24,7 +24,6 @@ and warmers.
* <<indices-put-mapping>> * <<indices-put-mapping>>
* <<indices-get-mapping>> * <<indices-get-mapping>>
* <<indices-get-field-mapping>> * <<indices-get-field-mapping>>
* <<indices-delete-mapping>>
* <<indices-types-exists>> * <<indices-types-exists>>
[float] [float]
@ -82,8 +81,6 @@ include::indices/get-field-mapping.asciidoc[]
include::indices/types-exists.asciidoc[] include::indices/types-exists.asciidoc[]
include::indices/delete-mapping.asciidoc[]
include::indices/aliases.asciidoc[] include::indices/aliases.asciidoc[]
include::indices/update-settings.asciidoc[] include::indices/update-settings.asciidoc[]

View File

@ -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.

View File

@ -170,6 +170,7 @@ A `RoutingMissingException` is now thrown instead.
=== Mappings === Mappings
* The setting `index.mapping.allow_type_wrapper` has been removed. Documents should always be sent without the type as the root element. * 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 ==== 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. Types can no longer be specified on fields within queries. Instead, specify type restrictions in the search request.

View File

@ -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: ''

View File

@ -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"

View File

@ -86,8 +86,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushAction;
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
import org.elasticsearch.action.admin.indices.get.GetIndexAction; import org.elasticsearch.action.admin.indices.get.GetIndexAction;
import org.elasticsearch.action.admin.indices.get.TransportGetIndexAction; 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.get.*;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction; import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction;
@ -254,7 +252,6 @@ public class ActionModule extends AbstractModule {
registerAction(GetMappingsAction.INSTANCE, TransportGetMappingsAction.class); registerAction(GetMappingsAction.INSTANCE, TransportGetMappingsAction.class);
registerAction(GetFieldMappingsAction.INSTANCE, TransportGetFieldMappingsAction.class, TransportGetFieldMappingsIndexAction.class); registerAction(GetFieldMappingsAction.INSTANCE, TransportGetFieldMappingsAction.class, TransportGetFieldMappingsIndexAction.class);
registerAction(PutMappingAction.INSTANCE, TransportPutMappingAction.class); registerAction(PutMappingAction.INSTANCE, TransportPutMappingAction.class);
registerAction(DeleteMappingAction.INSTANCE, TransportDeleteMappingAction.class);
registerAction(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class); registerAction(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class);
registerAction(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class); registerAction(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class);
registerAction(AnalyzeAction.INSTANCE, TransportAnalyzeAction.class); registerAction(AnalyzeAction.INSTANCE, TransportAnalyzeAction.class);

View File

@ -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<DeleteMappingRequest, DeleteMappingResponse, DeleteMappingRequestBuilder> {
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);
}
}

View File

@ -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<DeleteMappingClusterStateUpdateRequest> {
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;
}
}

View File

@ -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<DeleteMappingRequest> 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);
}
}

View File

@ -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<DeleteMappingRequest, DeleteMappingResponse, DeleteMappingRequestBuilder, IndicesAdminClient> {
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<DeleteMappingResponse> listener) {
client.deleteMapping(request, listener);
}
}

View File

@ -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);
}
}

View File

@ -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<DeleteMappingRequest, DeleteMappingResponse> {
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<DeleteMappingResponse> 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<DeleteMappingResponse> listener) throws ElasticsearchException {
final String[] concreteIndices = state.metaData().concreteIndices(request.indicesOptions(), request.indices());
flushAction.execute(new FlushRequest(request).indices(concreteIndices), new ActionListener<FlushResponse>() {
@Override
public void onResponse(FlushResponse flushResponse) {
if (logger.isTraceEnabled()) {
traceLogResponse("Flush", flushResponse);
}
// get all types that need to be deleted.
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> result = clusterService.state().metaData().findMappings(
concreteIndices, request.types()
);
// create OrFilter with type filters within to account for different types
BoolFilterBuilder filterBuilder = new BoolFilterBuilder();
Set<String> types = new HashSet<>();
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> typesMeta : result) {
for (ObjectObjectCursor<String, MappingMetaData> 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<DeleteByQueryResponse>() {
@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<RefreshResponse>() {
@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<ClusterStateUpdateResponse>() {
@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());
}
}
}
}

View File

@ -56,9 +56,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; 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.get.*;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
@ -438,29 +435,6 @@ public interface IndicesAdminClient extends ElasticsearchClient<IndicesAdminClie
*/ */
PutMappingRequestBuilder preparePutMapping(String... indices); PutMappingRequestBuilder preparePutMapping(String... indices);
/**
* Deletes mapping (and all its data) from one or more indices.
*
* @param request The delete mapping request
* @return A result future
* @see org.elasticsearch.client.Requests#deleteMappingRequest(String...)
*/
ActionFuture<DeleteMappingResponse> 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<DeleteMappingResponse> listener);
/**
* Deletes mapping definition for a type into one or more indices.
*/
DeleteMappingRequestBuilder prepareDeleteMapping(String... indices);
/** /**
* Allows to add/remove aliases from indices. * Allows to add/remove aliases from indices.
* *

View File

@ -44,7 +44,6 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; 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.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
@ -277,17 +276,6 @@ public class Requests {
return new PutMappingRequest(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 <tt>null</tt> or <tt>_all</tt> 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. * Creates an index aliases request allowing to add and remove aliases.
* *

View File

@ -67,10 +67,6 @@ import org.elasticsearch.action.admin.indices.get.GetIndexAction;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; 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.get.*;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
@ -374,21 +370,6 @@ public abstract class AbstractIndicesAdminClient implements IndicesAdminClient {
return new PutMappingRequestBuilder(this).setIndices(indices); return new PutMappingRequestBuilder(this).setIndices(indices);
} }
@Override
public ActionFuture<DeleteMappingResponse> deleteMapping(final DeleteMappingRequest request) {
return execute(DeleteMappingAction.INSTANCE, request);
}
@Override
public void deleteMapping(final DeleteMappingRequest request, final ActionListener<DeleteMappingResponse> listener) {
execute(DeleteMappingAction.INSTANCE, request, listener);
}
@Override
public DeleteMappingRequestBuilder prepareDeleteMapping(String... indices) {
return new DeleteMappingRequestBuilder(this).setIndices(indices);
}
@Override @Override
public ActionFuture<OptimizeResponse> optimize(final OptimizeRequest request) { public ActionFuture<OptimizeResponse> optimize(final OptimizeRequest request) {
return execute(OptimizeAction.INSTANCE, request); return execute(OptimizeAction.INSTANCE, request);

View File

@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.elasticsearch.action.ActionListener; 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.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest;
import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
@ -407,54 +406,6 @@ public class MetaDataMappingService extends AbstractComponent {
}); });
} }
public void removeMapping(final DeleteMappingClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {
clusterService.submitStateUpdateTask("remove-mapping [" + Arrays.toString(request.types()) + "]", Priority.HIGH, new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(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<ClusterStateUpdateResponse> listener) { public void putMapping(final PutMappingClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {
clusterService.submitStateUpdateTask("put-mapping [" + request.type() + "]", Priority.HIGH, new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(request, listener) { clusterService.submitStateUpdateTask("put-mapping [" + request.type() + "]", Priority.HIGH, new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(request, listener) {

View File

@ -60,7 +60,6 @@ import org.elasticsearch.rest.action.admin.indices.exists.indices.RestIndicesExi
import org.elasticsearch.rest.action.admin.indices.exists.types.RestTypesExistsAction; 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.flush.RestFlushAction;
import org.elasticsearch.rest.action.admin.indices.get.RestGetIndicesAction; 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.RestGetFieldMappingAction;
import org.elasticsearch.rest.action.admin.indices.mapping.get.RestGetMappingAction; import org.elasticsearch.rest.action.admin.indices.mapping.get.RestGetMappingAction;
import org.elasticsearch.rest.action.admin.indices.mapping.put.RestPutMappingAction; import org.elasticsearch.rest.action.admin.indices.mapping.put.RestPutMappingAction;
@ -181,7 +180,6 @@ public class RestActionModule extends AbstractModule {
bind(RestGetWarmerAction.class).asEagerSingleton(); bind(RestGetWarmerAction.class).asEagerSingleton();
bind(RestPutMappingAction.class).asEagerSingleton(); bind(RestPutMappingAction.class).asEagerSingleton();
bind(RestDeleteMappingAction.class).asEagerSingleton();
bind(RestGetMappingAction.class).asEagerSingleton(); bind(RestGetMappingAction.class).asEagerSingleton();
bind(RestGetFieldMappingAction.class).asEagerSingleton(); bind(RestGetFieldMappingAction.class).asEagerSingleton();

View File

@ -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<DeleteMappingResponse>(channel));
}
}

View File

@ -26,7 +26,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.WriteConsistencyLevel; 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.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
@ -36,14 +35,12 @@ import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Injectors;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.river.cluster.RiverClusterChangedEvent; import org.elasticsearch.river.cluster.RiverClusterChangedEvent;
import org.elasticsearch.river.cluster.RiverClusterService; import org.elasticsearch.river.cluster.RiverClusterService;
@ -214,37 +211,6 @@ public class RiversService extends AbstractLifecycleComponent<RiversService> {
if (routing == null || !localNode.equals(routing.node())) { if (routing == null || !localNode.equals(routing.node())) {
// not routed at all, and not allocated here, clean it (we delete the relevant ones before) // not routed at all, and not allocated here, clean it (we delete the relevant ones before)
closeRiver(riverName); 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<GetResponse>() {
@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<DeleteMappingResponse>() {
@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());
}
} }
} }

View File

@ -30,8 +30,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.flush.FlushAction; import org.elasticsearch.action.admin.indices.flush.FlushAction;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; 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.GetFieldMappingsAction;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
@ -609,19 +607,6 @@ public class IndicesRequestTests extends ElasticsearchIntegrationTest {
assertSameIndices(putMappingRequest, PutMappingAction.NAME); 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 @Test
public void testGetSettings() { public void testGetSettings() {
interceptTransportActions(GetSettingsAction.NAME); interceptTransportActions(GetSettingsAction.NAME);

View File

@ -63,13 +63,6 @@ public class BlockClusterStatsTests extends ElasticsearchIntegrationTest {
assertClusterAndIndexBlocks(e); assertClusterAndIndexBlocks(e);
} }
try {
client().admin().indices().prepareDeleteMapping("foo-alias").setType("test").get();
fail("delete mapping should have failed");
} catch(ClusterBlockException e) {
assertClusterAndIndexBlocks(e);
}
try { try {
client().admin().indices().preparePutMapping("foo-alias").setType("type1").setSource("field1", "type=string").get(); client().admin().indices().preparePutMapping("foo-alias").setType("type1").setSource("field1", "type=string").get();
fail("put mapping should have failed"); fail("put mapping should have failed");

View File

@ -27,10 +27,8 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.admin.indices.close.CloseIndexResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; 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.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; 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.settings.put.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse; import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse;
import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse;
@ -177,37 +175,6 @@ public class AckTests extends ElasticsearchIntegrationTest {
})); }));
} }
@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 @Test
public void testClusterRerouteAcknowledgement() throws InterruptedException { public void testClusterRerouteAcknowledgement() throws InterruptedException {
assertAcked(prepareCreate("test").setSettings(ImmutableSettings.builder() assertAcked(prepareCreate("test").setSettings(ImmutableSettings.builder()

View File

@ -630,46 +630,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest
assertThat(client().admin().indices().prepareExists("bar").get().isExists(), equalTo(false)); assertThat(client().admin().indices().prepareExists("bar").get().isExists(), equalTo(false));
assertThat(client().admin().indices().prepareExists("barbaz").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 @Test
public void testPutWarmer() throws Exception { public void testPutWarmer() throws Exception {
createIndex("foobar"); createIndex("foobar");
@ -727,37 +688,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("barbaz").get().exists(), equalTo(true)); 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 @Test
public void testDeleteWarmer() throws Exception { public void testDeleteWarmer() throws Exception {
IndexWarmersMetaData.Entry entry = new IndexWarmersMetaData.Entry( IndexWarmersMetaData.Entry entry = new IndexWarmersMetaData.Entry(

View File

@ -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) {}
}
}

View File

@ -144,36 +144,6 @@ public class DestructiveOperationsIntegrationTests extends ElasticsearchIntegrat
client().prepareDeleteByQuery().setQuery(QueryBuilders.matchAllQuery()).get(); client().prepareDeleteByQuery().setQuery(QueryBuilders.matchAllQuery()).get();
// end delete_by_query: // end delete_by_query:
client().admin().indices().prepareDelete("_all").get(); 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"));
} }
} }

View File

@ -1654,63 +1654,6 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
assertThat(matches[4].getHighlightFields().get("field1").fragments()[0].string(), equalTo("The quick brown <em>fox</em> jumps over the lazy dog")); assertThat(matches[4].getHighlightFields().get("field1").fragments()[0].string(), equalTo("The quick brown <em>fox</em> 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<Object>() {
@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) { public static String[] convertFromTextArray(PercolateResponse.Match[] matches, String index) {
if (matches.length == 0) { if (matches.length == 0) {
return Strings.EMPTY_ARRAY; return Strings.EMPTY_ARRAY;