From 3daa63a284777124482a1ca14ad162f384fa5093 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Mon, 20 Apr 2020 11:39:05 -0600 Subject: [PATCH 1/2] Change prefer_v2_templates parameter to default to true 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 --- .../migration/migrate_8_0/settings.asciidoc | 12 ++++++++++++ .../cluster/metadata/IndexMetadata.java | 2 +- .../indices/template/TemplatePreferenceIT.java | 12 ++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/reference/migration/migrate_8_0/settings.asciidoc b/docs/reference/migration/migrate_8_0/settings.asciidoc index 477cf4f83e806..0da51b2bf2c3b 100644 --- a/docs/reference/migration/migrate_8_0/settings.asciidoc +++ b/docs/reference/migration/migrate_8_0/settings.asciidoc @@ -77,3 +77,15 @@ In Elasticsearch 7.8.0, the following settings have been deprecated: In future releases, it will not be possible to disable the APIs for Enrichment, Flattened mappings, ILM, Monitoring, Rollup, SLM, SQL, Transforms, and Vectors. + +[float] +==== The `prefer_v2_templates` parameter now defaults to `true` + +In Elasticsearch 7.8.0 the `?prefer_v2_templates=true|false` parameter was introduced to allow +specifying whether to favor V1 or V2 templates when a new index is created. In 8.0 this now defaults +to `true`, meaning that V2 index templates will always take precedence if they match. V1 templates +will continue to be applied if no V2 index template matches the newly created index pattern. + +The `?prefer_v2_templates` parameter is supported on the <>, +<>, <>, <>, and +<> APIs. diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 09c4e677a1851..77f083021f6a9 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -249,7 +249,7 @@ public Iterator> settings() { // this is only setable internally not a registered setting!! public static final String PREFER_V2_TEMPLATES_FLAG = "prefer_v2_templates"; public static final String SETTING_PREFER_V2_TEMPLATES = "index." + PREFER_V2_TEMPLATES_FLAG; - public static final Setting PREFER_V2_TEMPLATES_SETTING = Setting.boolSetting(SETTING_PREFER_V2_TEMPLATES, false, + public static final Setting PREFER_V2_TEMPLATES_SETTING = Setting.boolSetting(SETTING_PREFER_V2_TEMPLATES, true, Property.Dynamic, Property.IndexScope); /** diff --git a/server/src/test/java/org/elasticsearch/indices/template/TemplatePreferenceIT.java b/server/src/test/java/org/elasticsearch/indices/template/TemplatePreferenceIT.java index c978a348b5926..2d5fc9193e2d4 100644 --- a/server/src/test/java/org/elasticsearch/indices/template/TemplatePreferenceIT.java +++ b/server/src/test/java/org/elasticsearch/indices/template/TemplatePreferenceIT.java @@ -69,7 +69,7 @@ public void cleanup() throws Exception { public void testCreateIndexPreference() throws Exception { client().admin().indices().prepareCreate(INDEX).get(); - assertUsedV1(); + assertUsedV2(); client().admin().indices().create(new CreateIndexRequest(INDEX).preferV2Templates(false)).get(); assertUsedV1(); @@ -80,7 +80,7 @@ public void testCreateIndexPreference() throws Exception { public void testIndexingRequestPreference() throws Exception { client().index(new IndexRequest(INDEX).source("foo", "bar")).get(); - assertUsedV1(); + assertUsedV2(); client().index(new IndexRequest(INDEX).source("foo", "bar").preferV2Templates(false)).get(); assertUsedV1(); @@ -89,7 +89,7 @@ public void testIndexingRequestPreference() throws Exception { assertUsedV2(); client().update(new UpdateRequest(INDEX, "1").doc("foo", "bar").docAsUpsert(true)).get(); - assertUsedV1(); + assertUsedV2(); client().update(new UpdateRequest(INDEX, "1").doc("foo", "bar").docAsUpsert(true).preferV2Templates(false)).get(); assertUsedV1(); @@ -98,7 +98,7 @@ public void testIndexingRequestPreference() throws Exception { assertUsedV2(); client().bulk(new BulkRequest(INDEX).add(new IndexRequest(INDEX).source("foo", "bar"))).get(); - assertUsedV1(); + assertUsedV2(); client().bulk(new BulkRequest(INDEX).add(new IndexRequest(INDEX).source("foo", "bar")).preferV2Templates(false)).get(); assertUsedV1(); @@ -115,8 +115,8 @@ public void testRolloverMaintainsSetting() throws Exception { client().admin().indices().prepareRolloverIndex("alias").get(); GetSettingsResponse resp = client().admin().indices().prepareGetSettings().setIndices(INDEX + "-000002").get(); - assertThat("expected index to use V1 template and have priority of 15", - resp.getSetting(INDEX + "-000002", "index.priority"), equalTo("15")); + assertThat("expected index to use V2 template and have priority of 23", + resp.getSetting(INDEX + "-000002", "index.priority"), equalTo("23")); client().admin().indices().prepareDelete(INDEX + "*").get(); } From 0ac7a434684af4db16d1f22f42404dcef968d341 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Mon, 20 Apr 2020 14:21:45 -0600 Subject: [PATCH 2/2] Change default in docs also --- docs/reference/api-conventions.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/api-conventions.asciidoc b/docs/reference/api-conventions.asciidoc index 24ec5621ad578..2274d3819d50d 100644 --- a/docs/reference/api-conventions.asciidoc +++ b/docs/reference/api-conventions.asciidoc @@ -385,7 +385,7 @@ Returns: "settings": { "index.number_of_replicas": "1", "index.number_of_shards": "1", - "index.prefer_v2_templates": "false", + "index.prefer_v2_templates": "true", "index.creation_date": "1474389951325", "index.uuid": "n6gzFZTgS664GUfx0Xrpjw", "index.version.created": ..., @@ -423,7 +423,7 @@ Returns: "created": ... }, "provided_name" : "twitter", - "prefer_v2_templates": "false" + "prefer_v2_templates": "true" } } }