Skip to content

Commit c1c7fa5

Browse files
authored
Remove type field from internal PutMappingRequest (elastic#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 elastic#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 18 deletions
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

Lines changed: 13 additions & 26 deletions
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

Lines changed: 0 additions & 8 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 6 deletions
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) {

0 commit comments

Comments
 (0)