Skip to content

Commit 58e0b48

Browse files
DaveCTurnergeorgewallace
authored andcommitted
Remove dead branches for v7 REST API (elastic#114850)
In v9 the `getRestApiVersion()` method on `RestRequest`, `XContentBuilder` and `XContentParser` can never return `V_7`, so we can replace all the expressions of the form `$x$.getRestApiVersion() == V_7` with `false`. This commit does that, and then refactors away the resulting dead code using (largely) automated transformations.
1 parent 5a6ae60 commit 58e0b48

File tree

72 files changed

+198
-996
lines changed

Some content is hidden

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

72 files changed

+198
-996
lines changed

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.client.internal.node.NodeClient;
1313
import org.elasticsearch.common.settings.Settings;
14-
import org.elasticsearch.core.RestApiVersion;
1514
import org.elasticsearch.rest.BaseRestHandler;
1615
import org.elasticsearch.rest.RestRequest;
1716
import org.elasticsearch.rest.Scope;
@@ -65,10 +64,6 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
6564
* Parses a {@link RestRequest} body and returns a {@link MultiSearchTemplateRequest}
6665
*/
6766
public static MultiSearchTemplateRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
68-
if (restRequest.getRestApiVersion() == RestApiVersion.V_7 && restRequest.hasParam("type")) {
69-
restRequest.param("type");
70-
}
71-
7267
MultiSearchTemplateRequest multiRequest = new MultiSearchTemplateRequest();
7368
if (restRequest.hasParam("max_concurrent_searches")) {
7469
multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
5555
import org.elasticsearch.index.mapper.LuceneDocument;
5656
import org.elasticsearch.index.mapper.MappedFieldType;
57-
import org.elasticsearch.index.mapper.MapperService;
5857
import org.elasticsearch.index.mapper.NestedLookup;
5958
import org.elasticsearch.index.mapper.ParsedDocument;
6059
import org.elasticsearch.index.mapper.SourceToParse;
@@ -312,9 +311,6 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
312311
if (indexedDocumentIndex != null) {
313312
builder.field(INDEXED_DOCUMENT_FIELD_INDEX.getPreferredName(), indexedDocumentIndex);
314313
}
315-
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
316-
builder.field(INDEXED_DOCUMENT_FIELD_TYPE.getPreferredName(), MapperService.SINGLE_MAPPING_NAME);
317-
}
318314
if (indexedDocumentId != null) {
319315
builder.field(INDEXED_DOCUMENT_FIELD_ID.getPreferredName(), indexedDocumentId);
320316
}

modules/reindex/src/main/java/org/elasticsearch/reindex/AbstractBulkByQueryRestHandler.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.common.bytes.BytesReference;
1515
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1616
import org.elasticsearch.common.xcontent.XContentHelper;
17-
import org.elasticsearch.core.RestApiVersion;
1817
import org.elasticsearch.features.NodeFeature;
1918
import org.elasticsearch.index.reindex.AbstractBulkByScrollRequest;
2019
import org.elasticsearch.index.reindex.BulkByScrollResponse;
@@ -28,7 +27,6 @@
2827
import java.io.IOException;
2928
import java.util.Map;
3029
import java.util.function.Consumer;
31-
import java.util.function.IntConsumer;
3230
import java.util.function.Predicate;
3331

3432
/**
@@ -54,10 +52,7 @@ protected void parseInternalRequest(
5452
SearchRequest searchRequest = internal.getSearchRequest();
5553

5654
try (XContentParser parser = extractRequestSpecificFields(restRequest, bodyConsumers)) {
57-
IntConsumer sizeConsumer = restRequest.getRestApiVersion() == RestApiVersion.V_7
58-
? size -> setMaxDocsFromSearchSize(internal, size)
59-
: size -> failOnSizeSpecified();
60-
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, clusterSupportsFeature, sizeConsumer);
55+
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, clusterSupportsFeature, size -> failOnSizeSpecified());
6156
}
6257

6358
searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size()));

modules/reindex/src/main/java/org/elasticsearch/reindex/RestUpdateByQueryAction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.reindex;
1111

1212
import org.elasticsearch.client.internal.node.NodeClient;
13-
import org.elasticsearch.core.RestApiVersion;
1413
import org.elasticsearch.features.NodeFeature;
1514
import org.elasticsearch.index.reindex.UpdateByQueryAction;
1615
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
@@ -55,9 +54,6 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
5554

5655
@Override
5756
protected UpdateByQueryRequest buildRequest(RestRequest request) throws IOException {
58-
if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("type")) {
59-
request.param("type");
60-
}
6157
/*
6258
* Passing the search request through UpdateByQueryRequest first allows
6359
* it to set its own defaults which differ from SearchRequest's

server/src/main/java/org/elasticsearch/action/DocWriteResponse.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.common.io.stream.StreamOutput;
1919
import org.elasticsearch.common.io.stream.Writeable;
2020
import org.elasticsearch.core.Nullable;
21-
import org.elasticsearch.core.RestApiVersion;
2221
import org.elasticsearch.index.IndexSettings;
2322
import org.elasticsearch.index.mapper.MapperService;
2423
import org.elasticsearch.index.seqno.SequenceNumbers;
@@ -298,9 +297,6 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t
298297
builder.field(_SEQ_NO, getSeqNo());
299298
builder.field(_PRIMARY_TERM, getPrimaryTerm());
300299
}
301-
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
302-
builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME);
303-
}
304300
return builder;
305301
}
306302

server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.common.io.stream.StreamOutput;
2020
import org.elasticsearch.common.settings.Settings;
2121
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
22-
import org.elasticsearch.core.RestApiVersion;
2322
import org.elasticsearch.index.mapper.MapperService;
2423
import org.elasticsearch.xcontent.ToXContent;
2524

@@ -30,9 +29,6 @@
3029
import java.util.Map;
3130
import java.util.Objects;
3231

33-
import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY;
34-
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
35-
3632
/**
3733
* A response for a get index action.
3834
*/
@@ -200,14 +196,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params ignore
200196
if (indexMappings == null) {
201197
builder.startObject("mappings").endObject();
202198
} else {
203-
if (builder.getRestApiVersion() == RestApiVersion.V_7
204-
&& params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY)) {
205-
builder.startObject("mappings");
206-
builder.field(MapperService.SINGLE_MAPPING_NAME, indexMappings.sourceAsMap());
207-
builder.endObject();
208-
} else {
209-
builder.field("mappings", indexMappings.sourceAsMap());
210-
}
199+
builder.field("mappings", indexMappings.sourceAsMap());
211200
}
212201

213202
builder.startObject("settings");

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
import org.elasticsearch.common.io.stream.StreamInput;
1616
import org.elasticsearch.common.io.stream.StreamOutput;
1717
import org.elasticsearch.common.xcontent.XContentHelper;
18-
import org.elasticsearch.core.RestApiVersion;
1918
import org.elasticsearch.index.mapper.Mapper;
2019
import org.elasticsearch.index.mapper.MapperService;
21-
import org.elasticsearch.rest.BaseRestHandler;
2220
import org.elasticsearch.xcontent.ParseField;
2321
import org.elasticsearch.xcontent.ToXContentFragment;
2422
import org.elasticsearch.xcontent.ToXContentObject;
@@ -31,8 +29,6 @@
3129
import java.util.Map;
3230
import java.util.Objects;
3331

34-
import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY;
35-
3632
/**
3733
* Response object for {@link GetFieldMappingsRequest} API
3834
*
@@ -91,16 +87,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9187
builder.startObject(indexEntry.getKey());
9288
builder.startObject(MAPPINGS.getPreferredName());
9389
if (indexEntry.getValue() != null) {
94-
if (builder.getRestApiVersion() == RestApiVersion.V_7
95-
&& params.paramAsBoolean(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY)) {
96-
if (indexEntry.getValue().size() > 0) {
97-
builder.startObject(MapperService.SINGLE_MAPPING_NAME);
98-
addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
99-
builder.endObject();
100-
}
101-
} else {
102-
addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
103-
}
90+
addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
10491
}
10592

10693
builder.endObject();

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.common.io.stream.StreamInput;
1818
import org.elasticsearch.common.io.stream.StreamOutput;
1919
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
20-
import org.elasticsearch.core.RestApiVersion;
2120
import org.elasticsearch.index.mapper.MapperService;
2221
import org.elasticsearch.xcontent.ParseField;
2322
import org.elasticsearch.xcontent.ToXContent;
@@ -26,9 +25,6 @@
2625
import java.util.Iterator;
2726
import java.util.Map;
2827

29-
import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY;
30-
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
31-
3228
public class GetMappingsResponse extends ActionResponse implements ChunkedToXContentObject {
3329

3430
private static final ParseField MAPPINGS = new ParseField("mappings");
@@ -73,16 +69,7 @@ public Iterator<ToXContent> toXContentChunked(ToXContent.Params outerParams) {
7369
Iterators.single((b, p) -> b.startObject()),
7470
Iterators.map(getMappings().entrySet().iterator(), indexEntry -> (builder, params) -> {
7571
builder.startObject(indexEntry.getKey());
76-
boolean includeTypeName = params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
77-
if (builder.getRestApiVersion() == RestApiVersion.V_7 && includeTypeName && indexEntry.getValue() != null) {
78-
builder.startObject(MAPPINGS.getPreferredName());
79-
80-
if (indexEntry.getValue() != MappingMetadata.EMPTY_MAPPINGS) {
81-
builder.field(MapperService.SINGLE_MAPPING_NAME, indexEntry.getValue().sourceAsMap());
82-
}
83-
builder.endObject();
84-
85-
} else if (indexEntry.getValue() != null) {
72+
if (indexEntry.getValue() != null) {
8673
builder.field(MAPPINGS.getPreferredName(), indexEntry.getValue().sourceAsMap());
8774
} else {
8875
builder.startObject(MAPPINGS.getPreferredName()).endObject();

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343
public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest {
4444

45-
private static final ObjectParser<RolloverRequest, Boolean> PARSER = new ObjectParser<>("rollover");
45+
private static final ObjectParser<RolloverRequest, Void> PARSER = new ObjectParser<>("rollover");
4646

4747
private static final ParseField CONDITIONS = new ParseField("conditions");
4848

@@ -57,27 +57,18 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
5757
CreateIndexRequest.SETTINGS,
5858
ObjectParser.ValueType.OBJECT
5959
);
60-
PARSER.declareField((parser, request, includeTypeName) -> {
61-
if (includeTypeName) {
62-
// expecting one type only
63-
for (Map.Entry<String, Object> mappingsEntry : parser.map().entrySet()) {
64-
@SuppressWarnings("unchecked")
65-
final Map<String, Object> value = (Map<String, Object>) mappingsEntry.getValue();
66-
request.createIndexRequest.mapping(value);
67-
}
68-
} else {
69-
// a type is not included, add a dummy _doc type
70-
Map<String, Object> mappings = parser.map();
71-
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) {
72-
throw new IllegalArgumentException(
73-
"The mapping definition cannot be nested under a type "
74-
+ "["
75-
+ MapperService.SINGLE_MAPPING_NAME
76-
+ "] unless include_type_name is set to true."
77-
);
78-
}
79-
request.createIndexRequest.mapping(mappings);
60+
PARSER.declareField((parser, request, context) -> {
61+
// a type is not included, add a dummy _doc type
62+
Map<String, Object> mappings = parser.map();
63+
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) {
64+
throw new IllegalArgumentException(
65+
"The mapping definition cannot be nested under a type "
66+
+ "["
67+
+ MapperService.SINGLE_MAPPING_NAME
68+
+ "] unless include_type_name is set to true."
69+
);
8070
}
71+
request.createIndexRequest.mapping(mappings);
8172
}, CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)), ObjectParser.ValueType.OBJECT);
8273
PARSER.declareField((parser, request, context) -> {
8374
// a type is not included, add a dummy _doc type
@@ -290,8 +281,8 @@ public CreateIndexRequest getCreateIndexRequest() {
290281
}
291282

292283
// param isTypeIncluded decides how mappings should be parsed from XContent
293-
public void fromXContent(boolean isTypeIncluded, XContentParser parser) throws IOException {
294-
PARSER.parse(parser, this, isTypeIncluded);
284+
public void fromXContent(XContentParser parser) throws IOException {
285+
PARSER.parse(parser, this, null);
295286
}
296287

297288
@Override

server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
import org.elasticsearch.action.support.broadcast.ChunkedBroadcastResponse;
1717
import org.elasticsearch.common.collect.Iterators;
1818
import org.elasticsearch.common.io.stream.StreamOutput;
19-
import org.elasticsearch.common.unit.ByteSizeValue;
2019
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
2120
import org.elasticsearch.core.Nullable;
22-
import org.elasticsearch.core.RestApiVersion;
2321
import org.elasticsearch.xcontent.ToXContent;
2422

2523
import java.io.IOException;
@@ -120,9 +118,6 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
120118
builder.field(Fields.NUM_DOCS, segment.getNumDocs());
121119
builder.field(Fields.DELETED_DOCS, segment.getDeletedDocs());
122120
builder.humanReadableField(Fields.SIZE_IN_BYTES, Fields.SIZE, segment.getSize());
123-
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
124-
builder.humanReadableField(Fields.MEMORY_IN_BYTES, Fields.MEMORY, ByteSizeValue.ZERO);
125-
}
126121
builder.field(Fields.COMMITTED, segment.isCommitted());
127122
builder.field(Fields.SEARCH, segment.isSearch());
128123
if (segment.getVersion() != null) {

0 commit comments

Comments
 (0)