Skip to content

Commit fc708cc

Browse files
authored
Remove prefer_v2_templates query string parameter (#56546)
This commit removes the `prefer_v2_templates` flag and setting. This was a brief setting that allowed specifying whether V1 or V2 template should be used when an index is created. It has been removed in favor of V2 templates always having priority. Relates to #53101 Resolves #56528 This is not a breaking change because this flag was never in a released version.
1 parent 0bf4be7 commit fc708cc

File tree

43 files changed

+32
-623
lines changed

Some content is hidden

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

43 files changed

+32
-623
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ static Request createIndex(CreateIndexRequest createIndexRequest) throws IOExcep
114114
parameters.withTimeout(createIndexRequest.timeout());
115115
parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout());
116116
parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards());
117-
if (createIndexRequest.preferV2Templates() != null) {
118-
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(createIndexRequest.preferV2Templates()));
119-
}
120117
request.addParameters(parameters.asMap());
121118
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
122119
return request;

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import org.elasticsearch.client.security.RefreshPolicy;
5757
import org.elasticsearch.client.tasks.TaskId;
5858
import org.elasticsearch.cluster.health.ClusterHealthStatus;
59-
import org.elasticsearch.cluster.metadata.IndexMetadata;
6059
import org.elasticsearch.common.Nullable;
6160
import org.elasticsearch.common.Priority;
6261
import org.elasticsearch.common.Strings;
@@ -133,9 +132,6 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {
133132
parameters.withRefreshPolicy(bulkRequest.getRefreshPolicy());
134133
parameters.withPipeline(bulkRequest.pipeline());
135134
parameters.withRouting(bulkRequest.routing());
136-
if (bulkRequest.preferV2Templates() != null) {
137-
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(bulkRequest.preferV2Templates()));
138-
}
139135
// Bulk API only supports newline delimited JSON or Smile. Before executing
140136
// the bulk, we need to check that all requests have the same content-type
141137
// and this content-type is supported by the Bulk API.
@@ -336,9 +332,6 @@ static Request index(IndexRequest indexRequest) {
336332
parameters.withPipeline(indexRequest.getPipeline());
337333
parameters.withRefreshPolicy(indexRequest.getRefreshPolicy());
338334
parameters.withWaitForActiveShards(indexRequest.waitForActiveShards());
339-
if (indexRequest.preferV2Templates() != null) {
340-
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(indexRequest.preferV2Templates()));
341-
}
342335

343336
BytesRef source = indexRequest.source().toBytesRef();
344337
ContentType contentType = createContentType(indexRequest.getContentType());
@@ -365,9 +358,6 @@ static Request update(UpdateRequest updateRequest) throws IOException {
365358
parameters.withRetryOnConflict(updateRequest.retryOnConflict());
366359
parameters.withVersion(updateRequest.version());
367360
parameters.withVersionType(updateRequest.versionType());
368-
if (updateRequest.preferV2Templates() != null) {
369-
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(updateRequest.preferV2Templates()));
370-
}
371361

372362
// The Java API allows update requests with different content types
373363
// set for the partial document and the upsert document. This client
@@ -579,10 +569,6 @@ private static Request prepareReindexRequest(ReindexRequest reindexRequest, bool
579569
params.putParam("scroll", reindexRequest.getScrollTime());
580570
}
581571

582-
if (reindexRequest.preferV2Templates() != null) {
583-
params.putParam("prefer_v2_templates", reindexRequest.preferV2Templates().toString());
584-
}
585-
586572
request.addParameters(params.asMap());
587573
request.setEntity(createEntity(reindexRequest, REQUEST_BODY_CONTENT_TYPE));
588574
return request;

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CreateIndexRequest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.action.support.ActiveShardCount;
2626
import org.elasticsearch.client.TimedRequest;
2727
import org.elasticsearch.client.Validatable;
28-
import org.elasticsearch.common.Nullable;
2928
import org.elasticsearch.common.ParseField;
3029
import org.elasticsearch.common.Strings;
3130
import org.elasticsearch.common.bytes.BytesArray;
@@ -63,7 +62,6 @@ public class CreateIndexRequest extends TimedRequest implements Validatable, ToX
6362

6463
private BytesReference mappings;
6564
private XContentType mappingsXContentType;
66-
private Boolean preferV2Templates;
6765

6866
private final Set<Alias> aliases = new HashSet<>();
6967

@@ -267,16 +265,6 @@ public CreateIndexRequest aliases(Collection<Alias> aliases) {
267265
return this;
268266
}
269267

270-
public CreateIndexRequest preferV2Templates(Boolean preferV2Templates) {
271-
this.preferV2Templates = preferV2Templates;
272-
return this;
273-
}
274-
275-
@Nullable
276-
public Boolean preferV2Templates() {
277-
return this.preferV2Templates;
278-
}
279-
280268
/**
281269
* Sets the settings and mappings as a single source.
282270
*

client/rest-high-level/src/test/java/org/elasticsearch/client/ReindexIT.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@
2323
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
2424
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
2525
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
26-
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
2726
import org.elasticsearch.action.bulk.BulkItemResponse;
2827
import org.elasticsearch.action.bulk.BulkRequest;
2928
import org.elasticsearch.action.get.GetRequest;
3029
import org.elasticsearch.action.index.IndexRequest;
3130
import org.elasticsearch.action.ingest.PutPipelineRequest;
3231
import org.elasticsearch.action.search.SearchRequest;
3332
import org.elasticsearch.action.support.WriteRequest;
34-
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
35-
import org.elasticsearch.client.indices.PutIndexTemplateV2Request;
3633
import org.elasticsearch.client.tasks.TaskSubmissionResponse;
37-
import org.elasticsearch.cluster.metadata.AliasMetadata;
38-
import org.elasticsearch.cluster.metadata.IndexTemplateV2;
39-
import org.elasticsearch.cluster.metadata.Template;
4034
import org.elasticsearch.common.CheckedRunnable;
4135
import org.elasticsearch.common.bytes.BytesReference;
4236
import org.elasticsearch.common.settings.Settings;
@@ -56,9 +50,6 @@
5650

5751
import java.io.IOException;
5852
import java.util.Collections;
59-
import java.util.HashMap;
60-
import java.util.List;
61-
import java.util.Map;
6253
import java.util.concurrent.CountDownLatch;
6354
import java.util.concurrent.TimeUnit;
6455
import java.util.stream.Collectors;
@@ -122,44 +113,6 @@ public void testReindex() throws IOException {
122113
}
123114
}
124115

125-
public void testReindexPreferV2Templates() throws Exception {
126-
//we don't care about warnings here
127-
RequestOptions options = RequestOptions.DEFAULT.toBuilder().setWarningsHandler(warnings -> false).build();
128-
129-
IndexRequest indexRequest = new IndexRequest("sourcev2").source(Collections.singletonMap("foo", "bar"), XContentType.JSON);
130-
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
131-
RestHighLevelClient client = highLevelClient();
132-
assertEquals(RestStatus.CREATED, client.index(indexRequest, options).status());
133-
134-
PutIndexTemplateRequest putIndexTemplateRequest = new PutIndexTemplateRequest("v1", Collections.singletonList("target*"));
135-
assertTrue(client.indices().putTemplate(putIndexTemplateRequest, options).isAcknowledged());
136-
137-
AliasMetadata alias = AliasMetadata.builder("alias").build();
138-
Template template = new Template(null, null, Map.of("alias", alias));
139-
List<String> pattern = Collections.singletonList("target*");
140-
IndexTemplateV2 indexTemplate = new IndexTemplateV2(pattern, template, Collections.emptyList(), 1L, 1L, new HashMap<>());
141-
PutIndexTemplateV2Request putTemplateRequest = new PutIndexTemplateV2Request().name("v2").indexTemplate(indexTemplate);
142-
assertTrue(client.indices().putIndexTemplate(putTemplateRequest, options).isAcknowledged());
143-
144-
ReindexRequest reindexRequest = new ReindexRequest()
145-
.preferV2Templates(true)
146-
.setSourceIndices("sourcev2")
147-
.setDestIndex("target1")
148-
.setRefresh(true);
149-
assertEquals(1, client.reindex(reindexRequest, options).getStatus().getSuccessfullyProcessed());
150-
151-
GetAliasesResponse aliases = client.indices().getAlias(new GetAliasesRequest().indices("target1"), options);
152-
assertEquals(RestStatus.OK, aliases.status());
153-
assertEquals(Collections.singletonMap("target1", Collections.singleton(alias)), aliases.getAliases());
154-
155-
reindexRequest.setDestIndex("target2").preferV2Templates(false);
156-
assertEquals(1, client.reindex(reindexRequest, options).getStatus().getSuccessfullyProcessed());
157-
158-
aliases = client.indices().getAlias(new GetAliasesRequest().indices("target2"), options);
159-
assertEquals(RestStatus.OK, aliases.status());
160-
assertEquals(Collections.singletonMap("target2", Collections.emptySet()), aliases.getAliases());
161-
}
162-
163116
public void testReindexTask() throws Exception {
164117
final String sourceIndex = "source123";
165118
final String destinationIndex = "dest2";

docs/reference/api-conventions.asciidoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ Returns:
385385
"settings": {
386386
"index.number_of_replicas": "1",
387387
"index.number_of_shards": "1",
388-
"index.prefer_v2_templates": "true",
389388
"index.creation_date": "1474389951325",
390389
"index.uuid": "n6gzFZTgS664GUfx0Xrpjw",
391390
"index.version.created": ...,
@@ -422,8 +421,7 @@ Returns:
422421
"version": {
423422
"created": ...
424423
},
425-
"provided_name" : "twitter",
426-
"prefer_v2_templates": "true"
424+
"provided_name" : "twitter"
427425
}
428426
}
429427
}

docs/reference/indices/index-templates.asciidoc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ This documentation is about V2 (version 2) index templates. For V1 templates ple
99

1010
[NOTE]
1111
====
12-
In {es} 7.8 the `prefer_v2_templates` querystring parameter was introduced to the index, update,
13-
bulk, and create index APIs to allow configuring whether to favor V2 or V1 index templates. In 7.x
14-
the default value for this parameter is `false` meaning that the <<indices-templates-v1,V1 index
15-
templates>> take precedence. In 8.x the default value for the parameter is `true` meaning that V2
16-
index templates take precedence (V1 templates may still match if no V2 template matches).
12+
In {es} 7.8 V2 templates were introduced. When a V2 index template matches a given index it always
13+
takes precedence over a V1 template. If no V2 index template matches, a V1 template may still match
14+
and be applied.
1715
====
1816

1917
An index template is a way to tell {es} how to configure an index when it is created. Templates are

docs/reference/indices/templates.asciidoc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ replaced by V2 templates. For information about V2 templates, see <<indices-temp
99

1010
[NOTE]
1111
====
12-
In {es} 7.8 the `prefer_v2_templates` querystring parameter was introduced to the index, update,
13-
bulk, and create index APIs to allow configuring whether to favor V2 or V1 index templates. In 7.x
14-
the default value for this parameter is `false` meaning that the V1 index templates take precedence.
15-
In 8.x the default value for the parameter is `true` meaning that <<indices-templates,V2 index
16-
templates>> take precedence (V1 templates may still match if no V2 template matches).
12+
In {es} 7.8 V2 templates were introduced. When a V2 index template matches a given index it always
13+
takes precedence over a V1 template. If no V2 index template matches, a V1 template may still match
14+
and be applied.
1715
====
1816

1917
Creates or updates an index template.

docs/reference/migration/migrate_8_0/settings.asciidoc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,3 @@ may be set to false.
144144
Discontinue use of the removed settings. Specifying these settings in
145145
`elasticsearch.yml` will result in an error on startup.
146146
====
147-
148-
.The `prefer_v2_templates` parameter now defaults to `true` for several document and index APIs.
149-
[%collapsible]
150-
====
151-
*Details* +
152-
In Elasticsearch 7.8.0 the `?prefer_v2_templates=true|false` parameter was introduced to allow
153-
specifying whether to favor V1 or V2 templates when a new index is created. In 8.0 this now defaults
154-
to `true`, meaning that V2 index templates will always take precedence if they match. V1 templates
155-
will continue to be applied if no V2 index template matches the newly created index pattern.
156-
157-
The `?prefer_v2_templates` parameter is supported on the <<indices-create-index,Create Index>>,
158-
<<docs-index_,Index>>, <<docs-bulk,Bulk>>, <<docs-update,Update>>, and
159-
<<indices-rollover-index,Rollover>> APIs.
160-
161-
*Impact* +
162-
Update your workflow and applications to assume a default value of `true` for
163-
the `prefer_v2_templates` query parameter.
164-
====

modules/reindex/src/main/java/org/elasticsearch/index/reindex/Reindexer.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.action.ActionListener;
3333
import org.elasticsearch.action.bulk.BackoffPolicy;
3434
import org.elasticsearch.action.bulk.BulkItemResponse;
35-
import org.elasticsearch.action.bulk.BulkRequest;
3635
import org.elasticsearch.action.index.IndexRequest;
3736
import org.elasticsearch.client.Client;
3837
import org.elasticsearch.client.ParentTaskAssigningClient;
@@ -218,11 +217,6 @@ public BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>>
218217
return super.buildScriptApplier();
219218
}
220219

221-
@Override
222-
protected BulkRequest buildBulk(Iterable<? extends ScrollableHitSource.Hit> docs) {
223-
return super.buildBulk(docs).preferV2Templates(mainRequest.preferV2Templates());
224-
}
225-
226220
@Override
227221
protected RequestWrapper<IndexRequest> buildRequest(ScrollableHitSource.Hit doc) {
228222
IndexRequest index = new IndexRequest();

modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ protected ReindexRequest buildRequest(RestRequest request) throws IOException {
6969
internal.setScroll(parseTimeValue(request.param("scroll"), "scroll"));
7070
}
7171

72-
if (request.hasParam("prefer_v2_templates")) {
73-
internal.preferV2Templates(Boolean.parseBoolean(request.param("prefer_v2_templates")));
74-
}
75-
7672
return internal;
7773
}
7874
}

0 commit comments

Comments
 (0)