Skip to content

Commit c1c7fa5

Browse files
authored
Remove type field from internal PutMappingRequest (#48793)
External API requests can no longer include types, so we have no need to pass this information along in internal PutMappingClusterStateUpdateRequest objects, or on PutMappingRequests used by the internal node client. Relates to #41059
1 parent 978a0e6 commit c1c7fa5

File tree

70 files changed

+188
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+188
-386
lines changed

modules/reindex/src/test/java/org/elasticsearch/client/documentation/ReindexDocumentationIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void testUpdateByQuery() {
101101
Client client = client();
102102
client.admin().indices().prepareCreate("foo").get();
103103
client.admin().indices().prepareCreate("bar").get();
104-
client.admin().indices().preparePutMapping(INDEX_NAME).setType("_doc").setSource("cat", "type=keyword").get();
104+
client.admin().indices().preparePutMapping(INDEX_NAME).setSource("cat", "type=keyword").get();
105105
{
106106
// tag::update-by-query
107107
UpdateByQueryRequestBuilder updateByQuery =

plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() thr
6363
jsonBuilder().startObject().startObject("properties").startObject("otherField").field("type", "text")
6464
.endObject().endObject().endObject();
6565
AcknowledgedResponse putMappingResponse =
66-
client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get();
66+
client().admin().indices().preparePutMapping(index).setSource(updateMappingBuilder).get();
6767
assertAcked(putMappingResponse);
6868

6969
// make sure size field is still in mapping
@@ -85,7 +85,7 @@ public void testThatSizeCanBeSwitchedOnAndOff() throws Exception {
8585
XContentBuilder updateMappingBuilder =
8686
jsonBuilder().startObject().startObject("_size").field("enabled", false).endObject().endObject();
8787
AcknowledgedResponse putMappingResponse =
88-
client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get();
88+
client().admin().indices().preparePutMapping(index).setSource(updateMappingBuilder).get();
8989
assertAcked(putMappingResponse);
9090

9191
// make sure size field is still in mapping

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingClusterStateUpdateRequest.java

+3-18
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,14 @@
2626
*/
2727
public class PutMappingClusterStateUpdateRequest extends IndicesClusterStateUpdateRequest<PutMappingClusterStateUpdateRequest> {
2828

29-
private String type;
29+
private final String source;
3030

31-
private String source;
32-
33-
public PutMappingClusterStateUpdateRequest() {
34-
35-
}
36-
37-
public String type() {
38-
return type;
39-
}
40-
41-
public PutMappingClusterStateUpdateRequest type(String type) {
42-
this.type = type;
43-
return this;
31+
public PutMappingClusterStateUpdateRequest(String source) {
32+
this.source = source;
4433
}
4534

4635
public String source() {
4736
return source;
4837
}
4938

50-
public PutMappingClusterStateUpdateRequest source(String source) {
51-
this.source = source;
52-
return this;
53-
}
5439
}

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java

+13-26
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.carrotsearch.hppc.ObjectHashSet;
2323
import org.elasticsearch.ElasticsearchGenerationException;
24+
import org.elasticsearch.Version;
2425
import org.elasticsearch.action.ActionRequestValidationException;
2526
import org.elasticsearch.action.IndicesRequest;
2627
import org.elasticsearch.action.support.IndicesOptions;
@@ -37,6 +38,7 @@
3738
import org.elasticsearch.common.xcontent.XContentHelper;
3839
import org.elasticsearch.common.xcontent.XContentType;
3940
import org.elasticsearch.index.Index;
41+
import org.elasticsearch.index.mapper.MapperService;
4042

4143
import java.io.IOException;
4244
import java.io.InputStream;
@@ -48,7 +50,7 @@
4850
import static org.elasticsearch.action.ValidateActions.addValidationError;
4951

5052
/**
51-
* Puts mapping definition registered under a specific type into one or more indices. Best created with
53+
* Puts mapping definition into one or more indices. Best created with
5254
* {@link org.elasticsearch.client.Requests#putMappingRequest(String...)}.
5355
* <p>
5456
* If the mappings already exists, the new mappings will be merged with the new one. If there are elements
@@ -69,8 +71,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
6971

7072
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true);
7173

72-
private String type;
73-
7474
private String source;
7575
private String origin = "";
7676

@@ -80,7 +80,12 @@ public PutMappingRequest(StreamInput in) throws IOException {
8080
super(in);
8181
indices = in.readStringArray();
8282
indicesOptions = IndicesOptions.readIndicesOptions(in);
83-
type = in.readOptionalString();
83+
if (in.getVersion().before(Version.V_8_0_0)) {
84+
String type = in.readOptionalString();
85+
if (MapperService.SINGLE_MAPPING_NAME.equals(type) == false) {
86+
throw new IllegalArgumentException("Expected type [_doc] but received [" + type + "]");
87+
}
88+
}
8489
source = in.readString();
8590
concreteIndex = in.readOptionalWriteable(Index::new);
8691
origin = in.readOptionalString();
@@ -100,11 +105,6 @@ public PutMappingRequest(String... indices) {
100105
@Override
101106
public ActionRequestValidationException validate() {
102107
ActionRequestValidationException validationException = null;
103-
if (type == null) {
104-
validationException = addValidationError("mapping type is missing", validationException);
105-
}else if (type.isEmpty()) {
106-
validationException = addValidationError("mapping type is empty", validationException);
107-
}
108108
if (source == null) {
109109
validationException = addValidationError("mapping source is missing", validationException);
110110
} else if (source.isEmpty()) {
@@ -160,21 +160,6 @@ public PutMappingRequest indicesOptions(IndicesOptions indicesOptions) {
160160
return this;
161161
}
162162

163-
/**
164-
* The mapping type.
165-
*/
166-
public String type() {
167-
return type;
168-
}
169-
170-
/**
171-
* The type of the mappings.
172-
*/
173-
public PutMappingRequest type(String type) {
174-
this.type = type;
175-
return this;
176-
}
177-
178163
/**
179164
* The mapping source definition.
180165
*/
@@ -190,7 +175,7 @@ public String source() {
190175
* mapping fields will automatically be put on the top level mapping object.
191176
*/
192177
public PutMappingRequest source(Object... source) {
193-
return source(buildFromSimplifiedDef(type, source));
178+
return source(buildFromSimplifiedDef(MapperService.SINGLE_MAPPING_NAME, source));
194179
}
195180

196181
public String origin() {
@@ -314,7 +299,9 @@ public void writeTo(StreamOutput out) throws IOException {
314299
super.writeTo(out);
315300
out.writeStringArrayNullable(indices);
316301
indicesOptions.writeIndicesOptions(out);
317-
out.writeOptionalString(type);
302+
if (out.getVersion().before(Version.V_8_0_0)) {
303+
out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME);
304+
}
318305
out.writeString(source);
319306
out.writeOptionalWriteable(concreteIndex);
320307
out.writeOptionalString(origin);

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java

-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ public PutMappingRequestBuilder setIndicesOptions(IndicesOptions options) {
5959
return this;
6060
}
6161

62-
/**
63-
* The type of the mappings.
64-
*/
65-
public PutMappingRequestBuilder setType(String type) {
66-
request.type(type);
67-
return this;
68-
}
69-
7062
/**
7163
* The mapping source definition.
7264
*/

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.transport.TransportService;
4444

4545
import java.io.IOException;
46+
import java.util.Arrays;
4647
import java.util.Objects;
4748
import java.util.Optional;
4849

@@ -105,10 +106,9 @@ protected void masterOperation(Task task, final PutMappingRequest request, final
105106
listener.onFailure(maybeValidationException.get());
106107
return;
107108
}
108-
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest()
109-
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
110-
.indices(concreteIndices).type(request.type())
111-
.source(request.source());
109+
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest(request.source())
110+
.indices(concreteIndices)
111+
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout());
112112

113113
metaDataMappingService.putMapping(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {
114114

@@ -119,14 +119,14 @@ public void onResponse(ClusterStateUpdateResponse response) {
119119

120120
@Override
121121
public void onFailure(Exception t) {
122-
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]",
123-
concreteIndices, request.type()), t);
122+
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}]",
123+
Arrays.asList(concreteIndices)), t);
124124
listener.onFailure(t);
125125
}
126126
});
127127
} catch (IndexNotFoundException ex) {
128-
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]",
129-
request.indices(), request.type()), ex);
128+
logger.debug(() -> new ParameterizedMessage("failed to put mappings on indices [{}]",
129+
Arrays.asList(request.indices())), ex);
130130
throw ex;
131131
}
132132
}

server/src/main/java/org/elasticsearch/action/bulk/MappingUpdatePerformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public interface MappingUpdatePerformer {
2828
/**
2929
* Update the mappings on the master.
3030
*/
31-
void updateMappings(Mapping update, ShardId shardId, String type, ActionListener<Void> listener);
31+
void updateMappings(Mapping update, ShardId shardId, ActionListener<Void> listener);
3232

3333
}

server/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ protected void shardOperationOnPrimary(BulkShardRequest request, IndexShard prim
121121
ActionListener<PrimaryResult<BulkShardRequest, BulkShardResponse>> listener) {
122122
ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
123123
performOnPrimary(request, primary, updateHelper, threadPool::absoluteTimeInMillis,
124-
(update, shardId, type, mappingListener) -> {
124+
(update, shardId, mappingListener) -> {
125125
assert update != null;
126126
assert shardId != null;
127-
mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), type, update, mappingListener);
127+
mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), update, mappingListener);
128128
},
129129
mappingUpdateListener -> observer.waitForNextChange(new ClusterStateObserver.Listener() {
130130
@Override
@@ -277,7 +277,6 @@ static boolean executeBulkItemRequest(BulkPrimaryExecutionContext context, Updat
277277
}
278278

279279
mappingUpdater.updateMappings(result.getRequiredMappingUpdate(), primary.shardId(),
280-
MapperService.SINGLE_MAPPING_NAME,
281280
new ActionListener<>() {
282281
@Override
283282
public void onResponse(Void v) {

server/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public void setClient(Client client) {
6969
* {@code timeout} is the master node timeout ({@link MasterNodeRequest#masterNodeTimeout()}),
7070
* potentially waiting for a master node to be available.
7171
*/
72-
public void updateMappingOnMaster(Index index, String type, Mapping mappingUpdate, ActionListener<Void> listener) {
73-
client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON)
72+
public void updateMappingOnMaster(Index index, Mapping mappingUpdate, ActionListener<Void> listener) {
73+
client.preparePutMapping().setConcreteIndex(index).setSource(mappingUpdate.toString(), XContentType.JSON)
7474
.setMasterNodeTimeout(dynamicMappingUpdateTimeout).setTimeout(TimeValue.ZERO)
7575
.execute(new ActionListener<AcknowledgedResponse>() {
7676
@Override

server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private ClusterState applyRequest(ClusterState currentState, PutMappingClusterSt
252252
updateList.add(indexMetaData);
253253
// try and parse it (no need to add it here) so we can bail early in case of parsing exception
254254
DocumentMapper existingMapper = mapperService.documentMapper();
255-
DocumentMapper newMapper = mapperService.parse(request.type(), mappingUpdateSource);
255+
DocumentMapper newMapper = mapperService.parse(MapperService.SINGLE_MAPPING_NAME, mappingUpdateSource);
256256
if (existingMapper != null) {
257257
// first, simulate: just call merge and ignore the result
258258
existingMapper.merge(newMapper.mapping());
@@ -272,7 +272,8 @@ private ClusterState applyRequest(ClusterState currentState, PutMappingClusterSt
272272
if (existingMapper != null) {
273273
existingSource = existingMapper.mappingSource();
274274
}
275-
DocumentMapper mergedMapper = mapperService.merge(request.type(), mappingUpdateSource, MergeReason.MAPPING_UPDATE);
275+
DocumentMapper mergedMapper
276+
= mapperService.merge(MapperService.SINGLE_MAPPING_NAME, mappingUpdateSource, MergeReason.MAPPING_UPDATE);
276277
CompressedXContent updatedSource = mergedMapper.mappingSource();
277278

278279
if (existingSource != null) {
@@ -322,10 +323,6 @@ private ClusterState applyRequest(ClusterState currentState, PutMappingClusterSt
322323
}
323324
}
324325

325-
@Override
326-
public String describeTasks(List<PutMappingClusterStateUpdateRequest> tasks) {
327-
return String.join(", ", tasks.stream().map(t -> (CharSequence)t.type())::iterator);
328-
}
329326
}
330327

331328
public void putMapping(final PutMappingClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1783,8 +1783,8 @@ public ShardPath shardPath() {
17831783
return path;
17841784
}
17851785

1786-
public void recoverFromLocalShards(BiConsumer<String, MappingMetaData> mappingUpdateConsumer, List<IndexShard> localShards,
1787-
ActionListener<Boolean> listener) throws IOException {
1786+
void recoverFromLocalShards(Consumer<MappingMetaData> mappingUpdateConsumer, List<IndexShard> localShards,
1787+
ActionListener<Boolean> listener) throws IOException {
17881788
assert shardRouting.primary() : "recover from local shards only makes sense if the shard is a primary shard";
17891789
assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS : "invalid recovery type: " +
17901790
recoveryState.getRecoverySource();
@@ -2462,7 +2462,7 @@ protected Engine getEngineOrNull() {
24622462

24632463
public void startRecovery(RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService,
24642464
PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService,
2465-
BiConsumer<String, MappingMetaData> mappingUpdateConsumer,
2465+
Consumer<MappingMetaData> mappingUpdateConsumer,
24662466
IndicesService indicesService) {
24672467
// TODO: Create a proper object to encapsulate the recovery context
24682468
// all of the current methods here follow a pattern of:

server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import java.util.List;
5757
import java.util.Set;
5858
import java.util.concurrent.atomic.AtomicBoolean;
59-
import java.util.function.BiConsumer;
59+
import java.util.function.Consumer;
6060
import java.util.stream.Collectors;
6161

6262
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
@@ -99,8 +99,8 @@ void recoverFromStore(final IndexShard indexShard, ActionListener<Boolean> liste
9999
}
100100
}
101101

102-
void recoverFromLocalShards(BiConsumer<String, MappingMetaData> mappingUpdateConsumer, IndexShard indexShard,
103-
List<LocalShardSnapshot> shards, ActionListener<Boolean> listener) {
102+
void recoverFromLocalShards(Consumer<MappingMetaData> mappingUpdateConsumer, final IndexShard indexShard,
103+
final List<LocalShardSnapshot> shards, ActionListener<Boolean> listener) {
104104
if (canRecover(indexShard)) {
105105
RecoverySource.Type recoveryType = indexShard.recoveryState().getRecoverySource().getType();
106106
assert recoveryType == RecoverySource.Type.LOCAL_SHARDS: "expected local shards recovery type: " + recoveryType;
@@ -113,7 +113,7 @@ void recoverFromLocalShards(BiConsumer<String, MappingMetaData> mappingUpdateCon
113113
}
114114
IndexMetaData sourceMetaData = shards.get(0).getIndexMetaData();
115115
if (sourceMetaData.mapping() != null) {
116-
mappingUpdateConsumer.accept(sourceMetaData.mapping().type(), sourceMetaData.mapping());
116+
mappingUpdateConsumer.accept(sourceMetaData.mapping());
117117
}
118118
indexShard.mapperService().merge(sourceMetaData, MapperService.MergeReason.MAPPING_RECOVERY);
119119
// now that the mapping is merged we can validate the index sort configuration.

server/src/main/java/org/elasticsearch/indices/IndicesService.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,11 @@ public IndexShard createShard(
652652
IndexShard indexShard = indexService.createShard(shardRouting, globalCheckpointSyncer, retentionLeaseSyncer);
653653
indexShard.addShardFailureCallback(onShardFailure);
654654
indexShard.startRecovery(recoveryState, recoveryTargetService, recoveryListener, repositoriesService,
655-
(type, mapping) -> {
655+
mapping -> {
656656
assert recoveryState.getRecoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS:
657657
"mapping update consumer only required by local shards recovery";
658658
client.admin().indices().preparePutMapping()
659659
.setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid
660-
.setType(type)
661660
.setSource(mapping.source().string(), XContentType.JSON)
662661
.get();
663662
}, this);

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java

-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public String getName() {
5757
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
5858
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
5959

60-
putMappingRequest.type(MapperService.SINGLE_MAPPING_NAME);
61-
6260
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false,
6361
request.getXContentType()).v2();
6462
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap)) {

server/src/main/java/org/elasticsearch/tasks/TaskResultsService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void onFailure(Exception e) {
131131
IndexMetaData metaData = state.getMetaData().index(TASK_INDEX);
132132
if (getTaskResultMappingVersion(metaData) < TASK_RESULT_MAPPING_VERSION) {
133133
// The index already exists but doesn't have our mapping
134-
client.admin().indices().preparePutMapping(TASK_INDEX).setType(TASK_TYPE)
134+
client.admin().indices().preparePutMapping(TASK_INDEX)
135135
.setSource(taskResultIndexMapping(), XContentType.JSON)
136136
.execute(ActionListener.delegateFailure(listener, (l, r) -> doStoreResult(taskResult, listener)));
137137
} else {

server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java

-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ public void testPutMapping() {
522522
interceptTransportActions(PutMappingAction.NAME);
523523

524524
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases())
525-
.type("type")
526525
.source("field", "type=text");
527526
internalCluster().coordOnlyNodeClient().admin().indices().putMapping(putMappingRequest).actionGet();
528527

server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public void testTransportBulkTasks() {
294294
createIndex("test");
295295
ensureGreen("test"); // Make sure all shards are allocated to catch replication tasks
296296
// ensures the mapping is available on all nodes so we won't retry the request (in case replicas don't have the right mapping).
297-
client().admin().indices().preparePutMapping("test").setType("doc").setSource("foo", "type=keyword").get();
297+
client().admin().indices().preparePutMapping("test").setSource("foo", "type=keyword").get();
298298
client().prepareBulk().add(client().prepareIndex("test").setId("test_id")
299299
.setSource("{\"foo\": \"bar\"}", XContentType.JSON)).get();
300300

0 commit comments

Comments
 (0)