Skip to content

Commit 942314f

Browse files
authored
Change prefer_v2_templates parameter to default to true (#55489)
As a followup to #55411, this commit changes the default for the `?prefer_v2_templates` querystring parameter to be `true`. This means that V2 templates will take precedence by default in 8.0+ Relates to #53101
1 parent e2fc95d commit 942314f

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

docs/reference/api-conventions.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Returns:
385385
"settings": {
386386
"index.number_of_replicas": "1",
387387
"index.number_of_shards": "1",
388-
"index.prefer_v2_templates": "false",
388+
"index.prefer_v2_templates": "true",
389389
"index.creation_date": "1474389951325",
390390
"index.uuid": "n6gzFZTgS664GUfx0Xrpjw",
391391
"index.version.created": ...,
@@ -423,7 +423,7 @@ Returns:
423423
"created": ...
424424
},
425425
"provided_name" : "twitter",
426-
"prefer_v2_templates": "false"
426+
"prefer_v2_templates": "true"
427427
}
428428
}
429429
}

docs/reference/migration/migrate_8_0/settings.asciidoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,15 @@ In Elasticsearch 7.8.0, the following settings have been deprecated:
7777

7878
In future releases, it will not be possible to disable the APIs for Enrichment,
7979
Flattened mappings, ILM, Monitoring, Rollup, SLM, SQL, Transforms, and Vectors.
80+
81+
[float]
82+
==== The `prefer_v2_templates` parameter now defaults to `true`
83+
84+
In Elasticsearch 7.8.0 the `?prefer_v2_templates=true|false` parameter was introduced to allow
85+
specifying whether to favor V1 or V2 templates when a new index is created. In 8.0 this now defaults
86+
to `true`, meaning that V2 index templates will always take precedence if they match. V1 templates
87+
will continue to be applied if no V2 index template matches the newly created index pattern.
88+
89+
The `?prefer_v2_templates` parameter is supported on the <<indices-create-index,Create Index>>,
90+
<<docs-index_,Index>>, <<docs-bulk,Bulk>>, <<docs-update,Update>>, and
91+
<<indices-rollover-index,Rollover>> APIs.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public Iterator<Setting<?>> settings() {
249249
// this is only setable internally not a registered setting!!
250250
public static final String PREFER_V2_TEMPLATES_FLAG = "prefer_v2_templates";
251251
public static final String SETTING_PREFER_V2_TEMPLATES = "index." + PREFER_V2_TEMPLATES_FLAG;
252-
public static final Setting<Boolean> PREFER_V2_TEMPLATES_SETTING = Setting.boolSetting(SETTING_PREFER_V2_TEMPLATES, false,
252+
public static final Setting<Boolean> PREFER_V2_TEMPLATES_SETTING = Setting.boolSetting(SETTING_PREFER_V2_TEMPLATES, true,
253253
Property.Dynamic, Property.IndexScope);
254254

255255
/**

server/src/test/java/org/elasticsearch/indices/template/TemplatePreferenceIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void cleanup() throws Exception {
6969

7070
public void testCreateIndexPreference() throws Exception {
7171
client().admin().indices().prepareCreate(INDEX).get();
72-
assertUsedV1();
72+
assertUsedV2();
7373

7474
client().admin().indices().create(new CreateIndexRequest(INDEX).preferV2Templates(false)).get();
7575
assertUsedV1();
@@ -80,7 +80,7 @@ public void testCreateIndexPreference() throws Exception {
8080

8181
public void testIndexingRequestPreference() throws Exception {
8282
client().index(new IndexRequest(INDEX).source("foo", "bar")).get();
83-
assertUsedV1();
83+
assertUsedV2();
8484

8585
client().index(new IndexRequest(INDEX).source("foo", "bar").preferV2Templates(false)).get();
8686
assertUsedV1();
@@ -89,7 +89,7 @@ public void testIndexingRequestPreference() throws Exception {
8989
assertUsedV2();
9090

9191
client().update(new UpdateRequest(INDEX, "1").doc("foo", "bar").docAsUpsert(true)).get();
92-
assertUsedV1();
92+
assertUsedV2();
9393

9494
client().update(new UpdateRequest(INDEX, "1").doc("foo", "bar").docAsUpsert(true).preferV2Templates(false)).get();
9595
assertUsedV1();
@@ -98,7 +98,7 @@ public void testIndexingRequestPreference() throws Exception {
9898
assertUsedV2();
9999

100100
client().bulk(new BulkRequest(INDEX).add(new IndexRequest(INDEX).source("foo", "bar"))).get();
101-
assertUsedV1();
101+
assertUsedV2();
102102

103103
client().bulk(new BulkRequest(INDEX).add(new IndexRequest(INDEX).source("foo", "bar")).preferV2Templates(false)).get();
104104
assertUsedV1();
@@ -115,8 +115,8 @@ public void testRolloverMaintainsSetting() throws Exception {
115115

116116
client().admin().indices().prepareRolloverIndex("alias").get();
117117
GetSettingsResponse resp = client().admin().indices().prepareGetSettings().setIndices(INDEX + "-000002").get();
118-
assertThat("expected index to use V1 template and have priority of 15",
119-
resp.getSetting(INDEX + "-000002", "index.priority"), equalTo("15"));
118+
assertThat("expected index to use V2 template and have priority of 23",
119+
resp.getSetting(INDEX + "-000002", "index.priority"), equalTo("23"));
120120
client().admin().indices().prepareDelete(INDEX + "*").get();
121121
}
122122

0 commit comments

Comments
 (0)