Skip to content

Commit 4bdd00d

Browse files
authored
[Rest Api Compatibility] Typed endpoint for bulk api (#73571)
retrofits typed endpoint and type in request parsing the original types removal commit #46983 relates #51816
1 parent f98b374 commit 4bdd00d

File tree

16 files changed

+120
-53
lines changed

16 files changed

+120
-53
lines changed

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
6363
bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
6464
bulkRequest.setRefreshPolicy(request.param("refresh"));
6565
bulkRequest.add(request.requiredContent(), defaultIndex, defaultRouting,
66-
null, defaultPipeline, defaultRequireAlias, true, request.getXContentType());
66+
null, defaultPipeline, defaultRequireAlias, true, request.getXContentType(),
67+
request.getRestApiVersion());
6768

6869
// short circuit the call to the transport layer
6970
return channel -> {

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,8 @@ XContentParser createParser(NamedXContentRegistry xContentRegistry, DeprecationH
8484
XContentParser createParserForCompatibility(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler,
8585
InputStream is, RestApiVersion restApiVersion) throws IOException;
8686

87+
XContentParser createParserForCompatibility(NamedXContentRegistry xContentRegistry,
88+
DeprecationHandler deprecationHandler, byte[] data, int offset, int length,
89+
RestApiVersion restApiVersion) throws IOException;
90+
8791
}

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,11 @@ public XContentParser createParserForCompatibility(NamedXContentRegistry xConten
105105
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(is), restApiVersion);
106106
}
107107

108+
@Override
109+
public XContentParser createParserForCompatibility(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler,
110+
byte[] data, int offset, int length, RestApiVersion restApiVersion)
111+
throws IOException {
112+
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(data, offset, length), restApiVersion);
113+
}
114+
108115
}

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,11 @@ public XContentParser createParserForCompatibility(NamedXContentRegistry xConten
105105
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(is), restApiVersion);
106106
}
107107

108+
@Override
109+
public XContentParser createParserForCompatibility(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler,
110+
byte[] data, int offset, int length, RestApiVersion restApiVersion)
111+
throws IOException {
112+
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(data, offset, length), restApiVersion);
113+
}
114+
108115
}

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ public XContentParser createParserForCompatibility(NamedXContentRegistry xConten
105105
RestApiVersion restApiVersion) throws IOException {
106106
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(is), restApiVersion);
107107
}
108+
109+
@Override
110+
public XContentParser createParserForCompatibility(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler,
111+
byte[] data, int offset, int length, RestApiVersion restApiVersion)
112+
throws IOException {
113+
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(data, offset, length),
114+
restApiVersion);
115+
}
108116
}

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,13 @@ public XContentParser createParserForCompatibility(NamedXContentRegistry xConten
9999
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(is), restApiVersion);
100100
}
101101

102+
@Override
103+
public XContentParser createParserForCompatibility(NamedXContentRegistry xContentRegistry,
104+
DeprecationHandler deprecationHandler, byte[] data, int offset, int length,
105+
RestApiVersion restApiVersion) throws IOException {
106+
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(data, offset, length),
107+
restApiVersion);
108+
}
109+
110+
102111
}

rest-api-spec/build.gradle

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ tasks.named("yamlRestCompatTest").configure {
122122
//type information is not stored, hence the the index will be found
123123
'termvectors/50_mix_typeless_typeful/Term vectors with typeless API on an index that has types',
124124
// 85 - 13 = 72 tests won't be fixed
125-
'bulk/11_basic_with_types/Array of objects',
126-
'bulk/11_basic_with_types/Empty _id',
127-
'bulk/11_basic_with_types/Empty _id with op_type create',
128-
'bulk/11_basic_with_types/empty action',
129-
'bulk/21_list_of_strings_with_types/List of strings',
130-
'bulk/31_big_string_with_types/One big string',
131-
'bulk/41_source_with_types/Source filtering',
132-
'bulk/51_refresh_with_types/refresh=empty string immediately makes changes are visible in search',
133-
'bulk/51_refresh_with_types/refresh=true immediately makes changes are visible in search',
134-
'bulk/51_refresh_with_types/refresh=wait_for waits until changes are visible in search',
135-
'bulk/81_cas_with_types/Compare And Swap Sequence Numbers',
136125
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion and specifying both node_ids and node_names',
137126
'cluster.voting_config_exclusions/10_basic/Throw exception when adding voting config exclusion without specifying nodes',
138127
'count/11_basic_with_types/count body without query element',

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.action.update.UpdateResponse;
1919
import org.elasticsearch.common.CheckedConsumer;
2020
import org.elasticsearch.common.ParseField;
21+
import org.elasticsearch.common.RestApiVersion;
2122
import org.elasticsearch.common.Strings;
2223
import org.elasticsearch.common.io.stream.StreamInput;
2324
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -64,6 +65,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
6465
builder.field(STATUS, response.status().getStatus());
6566
} else {
6667
builder.field(_INDEX, failure.getIndex());
68+
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
69+
builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME);
70+
}
71+
6772
builder.field(_ID, failure.getId());
6873
builder.field(STATUS, failure.getStatus().getStatus());
6974
builder.startObject(ERROR);
@@ -313,6 +318,9 @@ public boolean isAborted() {
313318
@Override
314319
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
315320
builder.field(INDEX_FIELD, index);
321+
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
322+
builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME);
323+
}
316324
if (id != null) {
317325
builder.field(ID_FIELD, id);
318326
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.action.index.IndexRequest;
1515
import org.elasticsearch.client.Client;
1616
import org.elasticsearch.common.Nullable;
17+
import org.elasticsearch.common.RestApiVersion;
1718
import org.elasticsearch.common.bytes.BytesReference;
1819
import org.elasticsearch.common.collect.Tuple;
1920
import org.elasticsearch.common.settings.Settings;
@@ -398,7 +399,7 @@ public BulkProcessor add(BytesReference data, @Nullable String defaultIndex,
398399
try {
399400
ensureOpen();
400401
bulkRequest.add(data, defaultIndex, null, null, defaultPipeline, null,
401-
true, xContentType);
402+
true, xContentType, RestApiVersion.current());
402403
bulkRequestToExecute = newBulkRequestIfNeeded();
403404
} finally {
404405
lock.unlock();

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.action.support.replication.ReplicationRequest;
2222
import org.elasticsearch.action.update.UpdateRequest;
2323
import org.elasticsearch.common.Nullable;
24+
import org.elasticsearch.common.RestApiVersion;
2425
import org.elasticsearch.common.Strings;
2526
import org.elasticsearch.common.bytes.BytesArray;
2627
import org.elasticsearch.common.bytes.BytesReference;
@@ -227,26 +228,26 @@ public BulkRequest add(byte[] data, int from, int length, @Nullable String defau
227228
*/
228229
public BulkRequest add(BytesReference data, @Nullable String defaultIndex,
229230
XContentType xContentType) throws IOException {
230-
return add(data, defaultIndex, null, null, null, null, true, xContentType);
231+
return add(data, defaultIndex, null, null, null, null, true, xContentType, RestApiVersion.current());
231232
}
232233

233234
/**
234235
* Adds a framed data in binary format
235236
*/
236237
public BulkRequest add(BytesReference data, @Nullable String defaultIndex, boolean allowExplicitIndex,
237238
XContentType xContentType) throws IOException {
238-
return add(data, defaultIndex, null, null, null, null, allowExplicitIndex, xContentType);
239+
return add(data, defaultIndex, null, null, null, null, allowExplicitIndex, xContentType, RestApiVersion.current());
239240

240241
}
241242

242243
public BulkRequest add(BytesReference data, @Nullable String defaultIndex,
243244
@Nullable String defaultRouting, @Nullable FetchSourceContext defaultFetchSourceContext,
244245
@Nullable String defaultPipeline, @Nullable Boolean defaultRequireAlias, boolean allowExplicitIndex,
245-
XContentType xContentType) throws IOException {
246+
XContentType xContentType, RestApiVersion restApiVersion) throws IOException {
246247
String routing = valueOrDefault(defaultRouting, globalRouting);
247248
String pipeline = valueOrDefault(defaultPipeline, globalPipeline);
248249
Boolean requireAlias = valueOrDefault(defaultRequireAlias, globalRequireAlias);
249-
new BulkRequestParser(true).parse(data, defaultIndex, routing, defaultFetchSourceContext, pipeline, requireAlias,
250+
new BulkRequestParser(true, restApiVersion).parse(data, defaultIndex, routing, defaultFetchSourceContext, pipeline, requireAlias,
250251
allowExplicitIndex, xContentType, (indexRequest, type) -> internalAdd(indexRequest), this::internalAdd, this::add);
251252
return this;
252253
}

0 commit comments

Comments
 (0)