Skip to content

Commit

Permalink
Remove prefer_v2_templates query string parameter (#56546)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dakrone authored May 11, 2020
1 parent 0bf4be7 commit fc708cc
Show file tree
Hide file tree
Showing 43 changed files with 32 additions and 623 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ static Request createIndex(CreateIndexRequest createIndexRequest) throws IOExcep
parameters.withTimeout(createIndexRequest.timeout());
parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout());
parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards());
if (createIndexRequest.preferV2Templates() != null) {
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(createIndexRequest.preferV2Templates()));
}
request.addParameters(parameters.asMap());
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.elasticsearch.client.security.RefreshPolicy;
import org.elasticsearch.client.tasks.TaskId;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -133,9 +132,6 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {
parameters.withRefreshPolicy(bulkRequest.getRefreshPolicy());
parameters.withPipeline(bulkRequest.pipeline());
parameters.withRouting(bulkRequest.routing());
if (bulkRequest.preferV2Templates() != null) {
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(bulkRequest.preferV2Templates()));
}
// Bulk API only supports newline delimited JSON or Smile. Before executing
// the bulk, we need to check that all requests have the same content-type
// and this content-type is supported by the Bulk API.
Expand Down Expand Up @@ -336,9 +332,6 @@ static Request index(IndexRequest indexRequest) {
parameters.withPipeline(indexRequest.getPipeline());
parameters.withRefreshPolicy(indexRequest.getRefreshPolicy());
parameters.withWaitForActiveShards(indexRequest.waitForActiveShards());
if (indexRequest.preferV2Templates() != null) {
parameters.putParam(IndexMetadata.PREFER_V2_TEMPLATES_FLAG, Boolean.toString(indexRequest.preferV2Templates()));
}

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

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

if (reindexRequest.preferV2Templates() != null) {
params.putParam("prefer_v2_templates", reindexRequest.preferV2Templates().toString());
}

request.addParameters(params.asMap());
request.setEntity(createEntity(reindexRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
Expand Down Expand Up @@ -63,7 +62,6 @@ public class CreateIndexRequest extends TimedRequest implements Validatable, ToX

private BytesReference mappings;
private XContentType mappingsXContentType;
private Boolean preferV2Templates;

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

Expand Down Expand Up @@ -267,16 +265,6 @@ public CreateIndexRequest aliases(Collection<Alias> aliases) {
return this;
}

public CreateIndexRequest preferV2Templates(Boolean preferV2Templates) {
this.preferV2Templates = preferV2Templates;
return this;
}

@Nullable
public Boolean preferV2Templates() {
return this.preferV2Templates;
}

/**
* Sets the settings and mappings as a single source.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.ingest.PutPipelineRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
import org.elasticsearch.client.indices.PutIndexTemplateV2Request;
import org.elasticsearch.client.tasks.TaskSubmissionResponse;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateV2;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.CheckedRunnable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -56,9 +50,6 @@

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -122,44 +113,6 @@ public void testReindex() throws IOException {
}
}

public void testReindexPreferV2Templates() throws Exception {
//we don't care about warnings here
RequestOptions options = RequestOptions.DEFAULT.toBuilder().setWarningsHandler(warnings -> false).build();

IndexRequest indexRequest = new IndexRequest("sourcev2").source(Collections.singletonMap("foo", "bar"), XContentType.JSON);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
RestHighLevelClient client = highLevelClient();
assertEquals(RestStatus.CREATED, client.index(indexRequest, options).status());

PutIndexTemplateRequest putIndexTemplateRequest = new PutIndexTemplateRequest("v1", Collections.singletonList("target*"));
assertTrue(client.indices().putTemplate(putIndexTemplateRequest, options).isAcknowledged());

AliasMetadata alias = AliasMetadata.builder("alias").build();
Template template = new Template(null, null, Map.of("alias", alias));
List<String> pattern = Collections.singletonList("target*");
IndexTemplateV2 indexTemplate = new IndexTemplateV2(pattern, template, Collections.emptyList(), 1L, 1L, new HashMap<>());
PutIndexTemplateV2Request putTemplateRequest = new PutIndexTemplateV2Request().name("v2").indexTemplate(indexTemplate);
assertTrue(client.indices().putIndexTemplate(putTemplateRequest, options).isAcknowledged());

ReindexRequest reindexRequest = new ReindexRequest()
.preferV2Templates(true)
.setSourceIndices("sourcev2")
.setDestIndex("target1")
.setRefresh(true);
assertEquals(1, client.reindex(reindexRequest, options).getStatus().getSuccessfullyProcessed());

GetAliasesResponse aliases = client.indices().getAlias(new GetAliasesRequest().indices("target1"), options);
assertEquals(RestStatus.OK, aliases.status());
assertEquals(Collections.singletonMap("target1", Collections.singleton(alias)), aliases.getAliases());

reindexRequest.setDestIndex("target2").preferV2Templates(false);
assertEquals(1, client.reindex(reindexRequest, options).getStatus().getSuccessfullyProcessed());

aliases = client.indices().getAlias(new GetAliasesRequest().indices("target2"), options);
assertEquals(RestStatus.OK, aliases.status());
assertEquals(Collections.singletonMap("target2", Collections.emptySet()), aliases.getAliases());
}

public void testReindexTask() throws Exception {
final String sourceIndex = "source123";
final String destinationIndex = "dest2";
Expand Down
4 changes: 1 addition & 3 deletions docs/reference/api-conventions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ Returns:
"settings": {
"index.number_of_replicas": "1",
"index.number_of_shards": "1",
"index.prefer_v2_templates": "true",
"index.creation_date": "1474389951325",
"index.uuid": "n6gzFZTgS664GUfx0Xrpjw",
"index.version.created": ...,
Expand Down Expand Up @@ -422,8 +421,7 @@ Returns:
"version": {
"created": ...
},
"provided_name" : "twitter",
"prefer_v2_templates": "true"
"provided_name" : "twitter"
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions docs/reference/indices/index-templates.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ This documentation is about V2 (version 2) index templates. For V1 templates ple

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

An index template is a way to tell {es} how to configure an index when it is created. Templates are
Expand Down
8 changes: 3 additions & 5 deletions docs/reference/indices/templates.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ replaced by V2 templates. For information about V2 templates, see <<indices-temp

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

Creates or updates an index template.
Expand Down
18 changes: 0 additions & 18 deletions docs/reference/migration/migrate_8_0/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,3 @@ may be set to false.
Discontinue use of the removed settings. Specifying these settings in
`elasticsearch.yml` will result in an error on startup.
====

.The `prefer_v2_templates` parameter now defaults to `true` for several document and index APIs.
[%collapsible]
====
*Details* +
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 <<indices-create-index,Create Index>>,
<<docs-index_,Index>>, <<docs-bulk,Bulk>>, <<docs-update,Update>>, and
<<indices-rollover-index,Rollover>> APIs.
*Impact* +
Update your workflow and applications to assume a default value of `true` for
the `prefer_v2_templates` query parameter.
====
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.bulk.BackoffPolicy;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.ParentTaskAssigningClient;
Expand Down Expand Up @@ -218,11 +217,6 @@ public BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>>
return super.buildScriptApplier();
}

@Override
protected BulkRequest buildBulk(Iterable<? extends ScrollableHitSource.Hit> docs) {
return super.buildBulk(docs).preferV2Templates(mainRequest.preferV2Templates());
}

@Override
protected RequestWrapper<IndexRequest> buildRequest(ScrollableHitSource.Hit doc) {
IndexRequest index = new IndexRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ protected ReindexRequest buildRequest(RestRequest request) throws IOException {
internal.setScroll(parseTimeValue(request.param("scroll"), "scroll"));
}

if (request.hasParam("prefer_v2_templates")) {
internal.preferV2Templates(Boolean.parseBoolean(request.param("prefer_v2_templates")));
}

return internal;
}
}
4 changes: 0 additions & 4 deletions rest-api-spec/src/main/resources/rest-api-spec/api/bulk.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@
"pipeline":{
"type":"string",
"description":"The pipeline id to preprocess incoming documents with"
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during automatic index creation"
}
},
"body":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@
"pipeline":{
"type":"string",
"description":"The pipeline id to preprocess incoming documents with"
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during automatic index creation"
}
},
"body":{
Expand Down
4 changes: 0 additions & 4 deletions rest-api-spec/src/main/resources/rest-api-spec/api/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@
"pipeline":{
"type":"string",
"description":"The pipeline id to preprocess incoming documents with"
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during automatic index creation"
}
},
"body":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
"master_timeout":{
"type":"time",
"description":"Specify timeout for connection to master"
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during index creation"
}
},
"body":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
"wait_for_active_shards":{
"type":"string",
"description":"Set the number of active shards to wait for on the newly created rollover index before the operation returns."
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during automatic index creation"
}
},
"body":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
"max_docs":{
"type":"number",
"description":"Maximum number of documents to process (default: all documents)"
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during index creation"
}
},
"body":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@
"if_primary_term":{
"type":"number",
"description":"only perform the update operation if the last operation that has changed the document has the specified primary term"
},
"prefer_v2_templates": {
"type": "boolean",
"description": "favor V2 templates instead of V1 templates during automatic index creation"
}
},
"body":{
Expand Down
Loading

0 comments on commit fc708cc

Please sign in to comment.